Question

Python Write your own unique Python program that has a runtime error. Do not copy the...

Python

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.

Homework Answers

Answer #1
Code:
-------
a = int(input("Enter numerator: "))
b = int(input("Enter denominator: "))
print("Division:",(a/b))


Output:
----------
Enter numerator: 5
Enter denominator: 0
Traceback (most recent call last):
  File "C:/Users/PyCharm/HelloWorld.py", line 3, in <module>
    print("Division:",(a//b))
ZeroDivisionError: integer division or modulo by zero


An explanation of the error message:
----------------------------------------
Error throws ZeroDivisionError when the denominator is zero

An explanation of how to fix the error:
----------------------------------------
We can add a check for denominator. If denominator is zero then print a message or ask for denominator again from user.

FIX:
-------
a = int(input("Enter numerator: "))
b = int(input("Enter denominator: "))
while(b==0):
    b = int(input("Denominator should not be zero. Please enter again: "))
print("Division:",(a/b))


Output:
---------
Enter numerator: 5
Enter denominator: 0
Denominator should not be zero. Please enter again: 2
Division: 2.5
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Python Invent your own function that does some useful computation of your choosing. Do not copy...
Python Invent your own function that does some useful computation of your choosing. Do not copy the function from somewhere else. Use incremental development, and record each stage of the development process as you go. Finally, print output that demonstrates that the function works as you intended. Include all of the following: An explanation of each stage of development, including code and any test input and output. The output of three calls to your function with different arguments.
Write a Python program prints out the unique elements of a list lst in a sorted...
Write a Python program prints out the unique elements of a list lst in a sorted manner (i.e it removes duplicates from the list). For example, if list is [10,20,30,20,10,50,60,40,80,50,40], the output should be [10, 20, 30, 40, 50, 60, 80].?
(in your own words do not copy off internet) includes your references or citation. What are...
(in your own words do not copy off internet) includes your references or citation. What are the greatest strengths and greatest weaknesses of political elections? What kind of change would you make in order to increase voters turnout in Texas? (make a minimum of two proposed changes. be very specific about proposed changes and provide explanation as to why and how your proposed changes will work.
Provide Python code that does the following: 4) Write a program that asks the user to...
Provide Python code that does the following: 4) Write a program that asks the user to enter a 9 character password. Test to see if it is a valid password. The validity test is a) they enter exactly 9 characters AND b) that every 3rd character, starting with the 1st character is the letter z. If it is valid print out the message “valid password” otherwise print the message “invalid password”. Sample output. Please enter a password: zaazbbz12 valid password...
I need python code for this. Write a program that inputs a text file. The program...
I need python code for this. Write a program that inputs a text file. The program should print the unique words in the file in alphabetical order. Uppercase words should take precedence over lowercase words. For example, 'Z' comes before 'a'. The input file can contain one or more sentences, or be a multiline list of words. An example input file is shown below: example.txt the quick brown fox jumps over the lazy dog An example of the program's output...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a...
Write a program IN PYTHON of the JUPYTER NOOTBOOK Write a Python program that gets a numeric grade (on a scale of 0-100) from the user and convert it to a letter grade based on the following table. Credit Score Annual Intrest Rate 500-649 %15.5 650-729 %9.5 730-800 %4.5 The program should be written so that if the user entered either a non-numeric input or a numeric input out of the 0-100 range, it asks him/her to enter a numeric...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using...
Please do it in Python Write the simplest program that will demonstrate iteration vs recursion using the following guidelines - Write two primary helper functions - one iterative (IsArrayPrimeIter) and one recursive (IsArrayPrimeRecur) - each of which Take the array and its size as input params and return a bool. Print out a message "Entering <function_name>" as the first statement of each function. Perform the code to test whether every element of the array is a Prime number. Print out...
The following code to run as the described program on python. The extra test file isn't...
The following code to run as the described program on python. The extra test file isn't included here, assume it is a text file named "TXT" with a series of numbers for this purpose. In this lab you will need to take a test file Your program must include: Write a python program to open the test file provided. You will read in the numbers contained in the file and provide a total for the numbers as well as the...
Write down the differences between perpetual and periodic method with examples in your own words. (Do...
Write down the differences between perpetual and periodic method with examples in your own words. (Do not copy from the internet)   
write two paragraphs about Enterococcus faecium. please use own simple words and do not copy from...
write two paragraphs about Enterococcus faecium. please use own simple words and do not copy from an internet source thank you....