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()

25th Sep 2019, 9:16 AM
Joshua Dominic
Joshua Dominic - avatar
1 Réponse
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")
25th Sep 2019, 10:23 AM
Russ
Russ - avatar
Aujourd'hui en vedette
.
1 Votes
What?
0 Votes
HTML
0 Votes
FRC Coding?
1 Votes
Quiz duel
0 Votes
AI
2 Votes
help
0 Votes
APIs
1 Votes
Create Agent
0 Votes