0
Why error invalid literal for base 10 coming out for the code below, when character string is given as input?
def tulis(): try: print("u typed ",Inser) except: print("u have typed character string,instead of integer") print("type a number") Inser = int(input()) tulis()
1 Answer
0
You need to put the statement...
Inser = int(input())
... in the try-except block. This is because, if a non-number is entered, it can't change it into an integer. I suggest you do something like the following:
def tulis():
print("u typed ",Inser)
print("type a number")
try:
Inser = int(input())
tulis()
except:
print("u have typed character string,instead of integer")