How shall i solve the data type issue of input? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How shall i solve the data type issue of input?

Here when you enter data other than integer it shows an error which i want to solve https://code.sololearn.com/cGiVcKoU426F/?ref=app

8th Oct 2019, 4:20 PM
harsh
harsh - avatar
2 Answers
+ 2
try ... except... does work this way: from sys import exit try: n=int(input('enter the 2 digit number you want to reverse')) except Exception as e: print(e) exit() else: if n>99: print('this program is meant only for 2 digit numbers.So,sorry.') else : x=n//10 y=n-x*10 N=(y*10)+x print('The number you entered was ',n) print("The number obtained by reversing places is ",N) All code that can cause an error should be in try: section. Code that should be executed in case of an error (in try: section ) should be in except: section. If no exception is raised, the code following the first else: will be executed.
8th Oct 2019, 7:39 PM
Lothar
Lothar - avatar
0
look up 'try, except' block.
8th Oct 2019, 5:05 PM
rodwynnejones
rodwynnejones - avatar