I need help with an assignment in which I have the user input two integers which will then perform division. If the numerator is 0, then it should print out 'INF', and same goes for the denominator.
a = 71
b = 4
a = 0
b = 4
a = 4
b = 0
This is my code so far:
#Calling out variables numerator_int = input("a = ") denominator_int = input("b = ") #The operands for the two user inputs quotient1_int = float(numerator_int)/float(denominator_int) quotient2_int = float(denominator_int)/float(numerator_int) #Numerator if if numerator_int == float(0): print numerator_int print("INF") #Denominator if elif denominator_int == float(0): print ("INF") print denominator_int #If both numerator and denominator is zero elif numerator_int and denominator_int == float(0): print ("INF") print ("INF") else: print quotient1_int print quotient2_int
When I run the code and input zero to the numerator or denominator, I get the error code claiming that when either number is on the denominator, it doesn't exist since dividing by zero is impossible.
How would I be able to overcome this?