***PLEASE WRITE OUT THE EXCAT CODE OR SCREEN SHOT FROM PYTHON**** (NO UNNECESSAR
ID: 3795684 • Letter: #
Question
***PLEASE WRITE OUT THE EXCAT CODE OR SCREEN SHOT FROM PYTHON**** (NO UNNECESSARY WORDS PLEASE)
Write a program that prompts for 3 numbers. Divide the first number by the second number and add the result to the third number. Using exceptions check for the following errors: ValueError, and Zero Division Error. Sample output: HOMEWORK/HW5/sol') Enter three integers (space separated): 3 0 8 Division by zero Error: 3/0 >>> HOMEWORK/HW5/sol') Enter three integers (space separated): 3 Hello 8 Value Error: 3 Hello 8 >>>Explanation / Answer
inp = raw_input("Enter three integers (space separated): ")
l = inp.split()
nums = []
for i in l:
try:
tmp = int(i)
nums.append(tmp)
except ValueError:
print("Value Error: "+inp)
exit()
try:
ans = (nums[0]*1.0)/nums[1]
except ZeroDivisionError:
print("Division by zero Error: "+l[0]+" / "+l[1])
exit()
print(ans+nums[2])
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.