how to use assert in try except block, please give any practical example | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to use assert in try except block, please give any practical example

25th Nov 2016, 9:50 AM
sajid
1 Answer
0
Are you asking how you would apply try except in your code in a practical way? if so, lets say you're making a calculator: try user=int(input("What's your first number?") #User input for for integer number except: print("Please type in a number") ''' Generally, you use try and except for when you're expecting an error due to faulty user input and you would inform the user with plain English rather than computer language '''
12th Jan 2017, 5:31 PM
Darth Vador
Darth Vador - avatar