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.
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
Get Answers For Free
Most questions answered within 1 hours.