Check a number | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 3

Check a number

how to check that a number is in a given input

5th Jun 2021, 3:28 AM
Somasundaram Puspagaran
Somasundaram Puspagaran - avatar
8 Answers
+ 2
Calvin Thomas isdigit() function will go on with it
5th Jun 2021, 4:39 AM
Atul [Inactive]
5th Jun 2021, 3:39 AM
Atul [Inactive]
+ 1
in addition to lisa, making two variables assigned with 2 inputs would be better. Ex: a = input() b = input() if b in a: print("True") else: print("False")
5th Jun 2021, 4:17 AM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar
+ 1
lisa The 'in' operator works only with strings.
5th Jun 2021, 4:38 AM
Calvin Thomas
Calvin Thomas - avatar
+ 1
Somasundaram Puspagaran Use try except block: try: x = int(input()) print (x) except: print ("Enter number only")
5th Jun 2021, 5:50 AM
A͢J
A͢J - avatar
0
i = input() num = 7 # keep any number here the number you want to check. if num in i: print("True") else: print("False")
5th Jun 2021, 4:11 AM
lisa
0
2 Inputs work too, since 'in' operator works only for strings including inputs.
5th Jun 2021, 4:40 AM
Dino Wun (Use the search bar plz!)
Dino Wun (Use the search bar plz!) - avatar
0
digit=5 inpu = 1256 print(str(digit) in str(inpu)) #True #------------------------------------------------# num = 5 inpu = "1256" print(str(digit) in str(inpu)) #True
5th Jun 2021, 6:14 AM
Ratnapal Shende
Ratnapal Shende - avatar