What the importamce of except statmen | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

What the importamce of except statmen

i dont cnow why we use exept

7th Feb 2018, 9:31 PM
‎‏‪‏‪‏‪‏‪‏‪‏‪imam‬‏‬‏‬‏‬‏‬‏‬‏‎
‎‏‪‏‪‏‪‏‪‏‪‏‪imam‬‏‬‏‬‏‬‏‬‏‬‏‎ - avatar
2 Answers
+ 4
You can use except to test the input of the user. try: x = int(input()) print(1/x) except: print("Please enter a number different from zero.") If anything go wrong with the code inside the try statement, the code inside the except statement will run. (For example, if the input equals zero or is a string etc.)
7th Feb 2018, 10:24 PM
Pedro Maimere
Pedro Maimere - avatar
+ 3
thank you
8th Feb 2018, 6:41 AM
‎‏‪‏‪‏‪‏‪‏‪‏‪imam‬‏‬‏‬‏‬‏‬‏‬‏‎
‎‏‪‏‪‏‪‏‪‏‪‏‪imam‬‏‬‏‬‏‬‏‬‏‬‏‎ - avatar