0

Question 1 of Exceptions and Handling

The only time I get the answer = "5.0 Finished" is when I run the code in sololearn's playground. When I type the code into Python Shell I get the following: >>> try: variable = 10 print(10/2) except ZeroDivisionError: print("ERROR") print("FINISHED") SyntaxError: invalid syntax >>> try: variable = 10 print(10/2) except ZeroDivisionError: print("ERROR") print("FINISHED") 5.0 >>> try: variable = 10 print(10/2) except ZeroDivisionError: print("ERROR") print("FINISHED") SyntaxError: unindent does not match any outer indentation level Everyone is saying how important the indent is. I have tried every way I can think of and cannot come up with the defined answer outside of sololearn's playground. Someone please show me where I am going wrong and how to make this work in shell. Show your work.

30th May 2017, 1:07 AM
A. Smith
13 Réponses
+ 1
5.0 finished
11th Sep 2018, 5:38 PM
Pallavi Gangadhar Savkar
+ 1
given code is incorrect, if we need to print 5.0 Finished then we have to code print("Finished") under try: because except will not be printed if there is no error in try >>> try: ... variable = 10 ... print(10/2) ... print("Finished") ... except ZeroDivisionError: ... print("Error") ... print("Finished") ... 5.0 Finished
29th Oct 2022, 3:19 PM
Rinku Rajbongshi
Rinku Rajbongshi - avatar
0
Remove the indent in the last line should be: try: variable = 10 print(10/2) except ZeroDivisionError: print("ERROR") print("FINISHED")
31st May 2017, 7:03 AM
Kreez
Kreez - avatar
0
That was on the first line which rendered: SyntaxError: invalid syntax.
31st May 2017, 7:25 AM
A. Smith
0
There is no error
31st May 2017, 7:29 AM
Kreez
Kreez - avatar
0
This is an interpreter error
31st May 2017, 7:29 AM
Kreez
Kreez - avatar
0
no
31st May 2017, 7:35 AM
Kreez
Kreez - avatar
0
Write to the support team about this error
31st May 2017, 7:36 AM
Kreez
Kreez - avatar
0
Thank you for your help.
31st May 2017, 7:38 AM
A. Smith
0
not at all))
31st May 2017, 7:39 AM
Kreez
Kreez - avatar
0
I think I have found the solution to my problem. Instead of typing this code into the shell itself; if I create a new file and save it, I can run it in module for the correct answer.
2nd Jun 2017, 6:51 PM
A. Smith
0
I guess this code is like this- try: variable = 10 print (10 / 2) except ZeroDivisionError: print("Error") print("Finished") However, the output should be - 5.0 Finished And not 5.0 Finished
3rd Dec 2017, 9:18 AM
Allison Wellington
- 1
Is there an easy way to correct this?
31st May 2017, 7:33 AM
A. Smith