How can I put only positive number in "input"? If someone puts negetive number values ,It will show error. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How can I put only positive number in "input"? If someone puts negetive number values ,It will show error.

AGE is always positive number

10th Nov 2020, 6:18 AM
Nafi Rahat Rahman
3 Answers
+ 9
You can also you if-else condition. If user enters a negative age then says that try again. # here is some code if age <= 0: print("Wrong input. Try again") else: # continue with your code here
10th Nov 2020, 6:21 AM
ツSampriya😘ツ
ツSampriya😘ツ - avatar
+ 3
use catch exeption
10th Nov 2020, 6:18 AM
Ananiya Jemberu
Ananiya Jemberu - avatar
+ 3
You can try the absolute function: abs(-16) // return 16
10th Nov 2020, 6:36 AM
ODLNT
ODLNT - avatar