Python Forum
Problem with basics - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Problem with basics (/thread-19196.html)



Problem with basics - Wraith2102 - Jun-17-2019

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?


RE: Problem with basics - noisefloor - Jun-17-2019

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


RE: Problem with basics - perfringo - Jun-17-2019

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).