Jun-17-2019, 05:56 PM
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?
Problem with basics
|
Jun-17-2019, 05:56 PM
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?
Jun-17-2019, 06:07 PM
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
Jun-17-2019, 06:51 PM
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).
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame. |
|
Possibly Related Threads… | |||||
Thread | Author | Replies | Views | Last Post | |
Learned Python Basics, what now? | muzikman | 20 | 9,039 |
Oct-11-2021, 01:34 AM Last Post: Underscore |
|
PYserial basics? | bako | 10 | 7,360 |
Apr-26-2020, 09:15 PM Last Post: bowlofred |
|
[split] Debugging scripts basics | tultalk | 5 | 4,160 |
Apr-25-2020, 01:02 AM Last Post: menator01 |
|
Debugging scripts basics | bako | 8 | 5,062 |
Apr-24-2020, 06:18 AM Last Post: Larz60+ |
|
Dictionary Basics | pythonjm | 5 | 4,564 |
Nov-26-2018, 11:11 PM Last Post: pythonjm |
|
What to do after learning python basics | xyzabc12310000 | 1 | 3,392 |
May-20-2018, 11:43 PM Last Post: micseydel |