Edit - here's the actual answer which I got with help from other students:
try:
user_num = int(input())
div_num = int(input())
quotient = int(user_num / div_num)
print(quotient)
except ValueError as value_error:
print(f'Input Exception: {value_error}')
except ZeroDivisionError as zero_error:
print(f'Zero Division Exception: integer division or modulo by zero')
Working on a class for intro to python, I have to get this specific lab done to 100% completion and I'm missing 1 point.
in my code we're tasked to.. Write a program that reads integers user_num and div_num as input, and output the quotient (user_num divided by div_num). Use a try block to perform all the statements. Use an except block to catch any ZeroDivisionError and output an exception message. Use another except block to catch any ValueError caused by invalid input and output an exception message. Note: ZeroDivisionError is thrown when a division by zero happens. ValueError is thrown when a user enters a value of different data type than what is defined in the program. Do not include code to throw any exception in the program.
try:
user_num = input()
div_num = input()
user_num = int(user_num)
div_num = int(div_num)
quotient = user_num // div_num
print(quotient)
except ZeroDivisionError:
if div_num == 0:
print("Zero Division Exception: integer division or modulo by zero")
except ValueError:
if user_num is not int:
print(f"Input Exception: invalid literal for int() with base 10: '{user_num}'")
except ValueError:
if div_num is not int:
print(f"Input Exception: invalid literal for int() with base 10: '{div_num}'")
Everything is working properly except the last final test that I need to get it through. With an user_num of 25 and div_num of 0.5 it SHOULD run the 2nd ValueError and not the 1st value error. When this code is ran it spits out Input Exception: invalid literal for int() with base 10: '25' Which to me doesn't make sense, I'm not sure how or what I can do to get the FIRST ValueError exception to either skip or pass so the actual 2nd ValueError can go through. Let it be noted that if the first input was a decimal it would still spit ONE error and one error only. Why is it stating the 25 is wrong when it's in fact a WHOLE number and not a decimal?