Answer to Question #99683 in Python for HAIDER

Question #99683
Write your own unique Python program that has a runtime error. Provide the following.

The code of your program.
Output demonstrating the runtime error, including the error message.
An explanation of the error message.
An explanation of how to fix the error.
1
Expert's answer
2019-12-01T13:14:08-0500

Program code: 

number = input("Enter an integer: ") 
number = int(number) 
print("Lucky!") 

An exception can occur in the third line of code when the value of the variable n is converted to an integer. If you enter the word “number”, you get an error:  ValueError: invalid literal for int() with base 10: 'numder'. Because you can't convert text to numbers. 

Error correction options: 

  1. number = input("Enter an integer: ") 
try: 
   number = int(number) 
   print("Lucky!") 
except: 
   print("Something went wrong") 
try: 
    number = input('Enter an integer: ') 
    number = int(number) 
    print("Everything is fine. You entered the number", number) 
except ValueError: 
    print("You did not enter an integer") 

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS