Answer to Question #274963 in Python for kika

Question #274963

2. Write your own unique Python program that has a runtime error. Do not copy the program from your textbook or the Internet. 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
2021-12-06T05:26:57-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