How can we only put integer as a input in python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can we only put integer as a input in python

19th Jun 2023, 4:34 AM
ARYAN JAT👑💯💯
ARYAN JAT👑💯💯 - avatar
5 Answers
+ 2
You can use int(input()) but your input should be able to handle if user enters non integer type..
19th Jun 2023, 12:08 PM
Bishnu Chalise
Bishnu Chalise - avatar
+ 5
ARYAN JAT👑💯💯 , do you mean, how we can make sure that only *digits* are given as input? try to describe your needs a bit more in detail. > maybe just give sample/s.
19th Jun 2023, 10:57 AM
Lothar
Lothar - avatar
+ 2
Int(input) Or better still create a function that checks if an input is digit or not. It handles error better
20th Jun 2023, 12:43 AM
Christabel
Christabel - avatar
+ 1
int(input())
19th Jun 2023, 4:53 AM
Hasnain [ACTIVE CHALLENGER]
Hasnain [ACTIVE CHALLENGER] - avatar
+ 1
You should convert the format of input to int
19th Jun 2023, 4:53 AM
Hasnain [ACTIVE CHALLENGER]
Hasnain [ACTIVE CHALLENGER] - avatar