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
2 Respuestas
+ 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.
0
look up  'try, except' block.



