0

Why does this code throw syntax errors?

This is in the Code Playground as divisibility_checker1. I don't understand why it throws a syntax error at line 16. If I remove the check for division by zero, line 21 will also throw a syntax error even though identical syntax is used successfully in line 9. What gives? Am I doing the while loops wrong? # cannot figure out why this does not work print("Check any number for divisibility by any other number!") x = 1.5 y = 1.5 while x - int(x) != 0: x = float(input("Enter the number to check, i.e. the dividend: ")) if x - int(x) != 0: print("Please enter a whole number, not a decimal.") while y - int(y) != 0: y = float(input("Enter the number to divide it by, i.e. the divisor: ") if y == 0: print("No dividing by zero. Please enter a different number.") y = 1.5 if y - int(y) != 0: print("Please enter a whole number, not a decimal.") int(x) int(y) if x%y=0: print(x + " is divisible by " + y + "!") else: print(x + " is not divisible by " + y + ".")

20th Oct 2016, 2:09 PM
Scivias
Scivias - avatar
2 Respuestas
+ 4
1)in line 15. " )" is missing this is the syntax error there are several other errors as well 2)line 27 : must be -> if x%y==0: (2 = signs) 3)line 24 and 25 don't do anything if you want to convert x and y to int use x=int(x) y=int(y) instead 4)change x and y to str(x) and str(y) in lines 28 and 30
20th Oct 2016, 2:27 PM
Sunera
Sunera - avatar
+ 1
Thank you... I fixed it and it works perfectly! I even added an option at the end for the user to check another number or exit.
20th Oct 2016, 4:31 PM
Scivias
Scivias - avatar