0

Hi,i want to get an integer from user . what should i do?

a=input("enter num : ") this is my code . but it gets a string. not an intiger

20th Nov 2017, 6:31 PM
samaneh alipour
samaneh alipour - avatar
16 Answers
+ 9
a = int(input("Enter number: ")) Try it out. It'll cast the string into int.
20th Nov 2017, 6:34 PM
Shamima Yasmin
Shamima Yasmin - avatar
+ 2
max = a for i in [a,b,c]: if i > max: max = i print(max)
20th Nov 2017, 8:34 PM
Oma Falk
Oma Falk - avatar
+ 2
max([a,b.c]) not max[a,b,c]
20th Nov 2017, 8:42 PM
Oma Falk
Oma Falk - avatar
+ 1
samanehs solution is very good. you can wrap a try/catch around it. will not work in sololearn
20th Nov 2017, 8:07 PM
Oma Falk
Oma Falk - avatar
+ 1
u know how to input in sololearn?
20th Nov 2017, 8:22 PM
Oma Falk
Oma Falk - avatar
+ 1
print(max[a,b,c])
20th Nov 2017, 8:30 PM
Oma Falk
Oma Falk - avatar
0
Thanks alot
20th Nov 2017, 8:13 PM
samaneh alipour
samaneh alipour - avatar
0
a=int(input("add\n")) b=int(input("add\n")) c=int(input("add\n")) if(a > b & a > c): print(a) else: if(b > a & b > c): print(b) else: if(c > a & c > b) print(c) this is my code but it dosn't work yet
20th Nov 2017, 8:21 PM
samaneh alipour
samaneh alipour - avatar
0
The if statement is not correct
20th Nov 2017, 8:21 PM
samaneh alipour
samaneh alipour - avatar
0
Do u know what should i do?
20th Nov 2017, 8:21 PM
samaneh alipour
samaneh alipour - avatar
0
yes for ex 1 press enter then 2 again press enter 3
20th Nov 2017, 8:23 PM
samaneh alipour
samaneh alipour - avatar
0
You can copy and try it yourself
20th Nov 2017, 8:28 PM
samaneh alipour
samaneh alipour - avatar
0
thanks for this . but do u know how can i use from for state?
20th Nov 2017, 8:31 PM
samaneh alipour
samaneh alipour - avatar
0
and i tried it . max[] . but it doesn't work too
20th Nov 2017, 8:34 PM
samaneh alipour
samaneh alipour - avatar
0
thanks . the last way worked ♥
20th Nov 2017, 8:38 PM
samaneh alipour
samaneh alipour - avatar
0
yes it worked
20th Nov 2017, 8:47 PM
samaneh alipour
samaneh alipour - avatar