0
Debug please
try: x = str(int(input())) if x==8: print("1st one") except: y = input() if y == "a": print("2nd chance") #code ends here Input a #input ends here Output Traceback (most recent call last): File "compiler.py", line 2, in x = str(int(input())) ValueError: invalid literal for int() with base 10: 'a' During handling of the above exception, another exception occurred: Traceback (most recent call last): File "compiler.py", line 6, in y = input() EOFError: EOF when reading a line
5 Respostas
0
Are you running this code in Playground? cause if you are, then you need to provide all the possibly required inputs in the input dialog (pops when you run the code).
The first error happened because 'a' (the input) is a non numeric, and hence int() failed to convert it into an integer.
A bit of info in case you didn't know; input() returns a string, so your code
x = str(int(input()))
Is kinda redundant, it tries converts string (from input()) into an integer, then it tries to convert again into a string.
The second error was because there was no more data to be read by input() function. This is triggered by the call to input() function inside the `except` block
y = input()
That's how I see it ...
+ 2
Before debugging, can you explain what you are trying to achieve through this code? I just don't have any idea what you're doing here.
0
Ipang nothing , just practicing “try and except “😔
0
Ipang thanks a “lot” * 1000 , it worked 🙂
0
No problem at all 👌