- 1

Why this int function doesnt accept float??

In the code a,b = map(int, input().split(',')) If I put 3.5,4.5 for a,b it doesnt work Only for int...but the int function makes float to int isnt it..? Help me guys

4th Jul 2021, 10:15 AM
Son
4 Antworten
+ 4
Nope ... Python can't convert a floatString to int. print(int(float("3.5")))
4th Jul 2021, 12:34 PM
Oma Falk
Oma Falk - avatar
+ 4
how about instead of mapping int() you map float()? https://code.sololearn.com/c5Y2xgp19mXs/?ref=app
4th Jul 2021, 10:51 AM
Slick
Slick - avatar
+ 2
a, b = (int(float(s)) for s in input().split(','))
4th Jul 2021, 3:13 PM
visph
visph - avatar
+ 1
# or (but much more verbose and slightly less efficient): a, b = map(lambda s: int(float(s)), input().split(','))
4th Jul 2021, 3:15 PM
visph
visph - avatar