0
Why is this code not working :(
so i've decided to make a calendar of 2022 and it worked. but then i thought there can be an error so i put the TRY...EXCEPT... block. but after i tried to test if it really catches exceptions i wrote nvalid syntax on purpose but it didin't go well... https://code.sololearn.com/cz8Yxr0JrXm9/?ref=app
8 Respuestas
+ 2
many people answered this but the problem is why is the except block not catching error
+ 1
Paul
SyntaxError is raised before the try-except block.
https://stackoverflow.com/questions/1856408/syntaxerror-inconsistency-in-JUMP_LINK__&&__python__&&__JUMP_LINK
+ 1
VISHAL H U
Altair Enigma intentionally added it.
The question is why the try-catch block did not catch the syntax error.
It was never about fixing the code, which is very obvious and simple.
0
Think the python course is a bit misleading, it says you can catch a SyntaxError. But this one is caught by the interpreter before the code can run.
0
Remove if in 8th line of code
0
Your code doesn't start running because of the syntax ertor.
0
Thanks for the link. I want to know about SyntaxError inconsistency in Python. I was actually looking for this https://letsgradeit.com/review/essaywriter/ website online because I don't know how to hire an essay writer and when I was searching for it onilne, I am glad I found link to your post as well.
- 1
try:
import time
import calendar
print ("Calender of 2022: ")
test = '''
print (calendar.month(2022, 1))
print (calendar.month(2022, 2))if
print (calendar.month(2022, 3))
print (calendar.month(2022, 4))
print (calendar.month(2022, 5))
print (calendar.month(2022, 6))
print (calendar.month(2022, 7))
print (calendar.month(2022, 8))
print (calendar.month(2022, 9))
print (calendar.month(2022, 10))
print (calendar.month(2022, 11))
print (calendar.month(2022, 12))
localtime = time.asctime(time. localtime(time.time()))
print ("Current local time :", localtime)'''
eval(test)
except SyntaxError:
print("Oops! there seems tobe something wrong.")