git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]# [Beginner] Spliting input

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Bischoop wrote: > I try to split input numbers, for example: 12 so I cant add them, I > tried separated split(' ') but it's not working. > Any ideas how to do this? > > * > numb1,numb2=input("enter 1st and 2nd no ").split() > Avg=(int(numb1) + int(numb2)) / 2 > print(Avg) > * > > -- > Thanks To split the string "12" into its characters (i. e. the digits "1" and "2") you don't need the split() method which only works with separators. Instead you can unpack the digits directly: >>> a, b = input("enter two digits> ") enter two digits> 12 >>> a '1' >>> b '2' >>> (int(a) + int(b)) / 2 1.5

- Prev by Date:
**[Beginner] Spliting input** - Next by Date:
**[Beginner] Spliting input** - Previous by thread:
**[Beginner] Spliting input** - Next by thread:
**[Beginner] Spliting input** - Index(es):