Why is this code not working :( | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

18th Sep 2022, 7:25 AM
Altair Enigma
Altair Enigma - avatar
8 Answers
+ 2
many people answered this but the problem is why is the except block not catching error
24th Sep 2022, 4:44 PM
Altair Enigma
Altair Enigma - avatar
18th Sep 2022, 2:18 PM
Bob_Li
Bob_Li - avatar
+ 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.
19th Sep 2022, 10:39 AM
Bob_Li
Bob_Li - avatar
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.
18th Sep 2022, 9:43 AM
Paul
Paul - avatar
0
Remove if in 8th line of code
19th Sep 2022, 9:51 AM
VISHAL H U
VISHAL H U - avatar
0
Your code doesn't start running because of the syntax ertor.
24th Sep 2022, 6:45 PM
Paul
Paul - avatar
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.
9th Oct 2022, 8:54 AM
Brandon Dye
- 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.")
18th Sep 2022, 2:16 PM
Bob_Li
Bob_Li - avatar