Python Forum

Full Version: Problem with basics
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
x=int(input('Enter x= ')
if x%2 == 0:
    if x%3 == 0:
        print('Divisible by 2 & 3')
    elif
        print('Divisible by 2 but not 3)
else
    print('Divisible by 3 but not 2)
print('')
What is the issue in this?
Hi,

Quote:What is the issue in this?
The question is more like: what's YOUR issue with that? Any error messages? Unexpected behavior?
This is a help forum, not a guessing game. Which means that we have no intention to guess what your problem is, YOU should to describe it.

But what I can say without guessing: your code has at least four errors and the else branch is
mathematically wrong. E.g. if x is prime, your code would say it's dividable by 3.

Regards, noisefloor
I also observe that the algorithm is not optimal.

In order to determine whether number is divisible by 2 and 3 you need to check whether number is divisible by 6 (2 * 3).