Debug please | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

8th Aug 2020, 1:05 PM
Md Anas Faisal
Md Anas Faisal - avatar
5 Answers
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 ...
8th Aug 2020, 1:30 PM
Ipang
+ 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.
8th Aug 2020, 1:14 PM
Ipang
0
Ipang nothing , just practicing “try and except “😔
8th Aug 2020, 1:17 PM
Md Anas Faisal
Md Anas Faisal - avatar
0
Ipang thanks a “lot” * 1000 , it worked 🙂
8th Aug 2020, 1:51 PM
Md Anas Faisal
Md Anas Faisal - avatar
0
No problem at all 👌
8th Aug 2020, 1:53 PM
Ipang