Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problem with basics
#1
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?
Reply
#2
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
Reply
#3
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Learned Python Basics, what now? muzikman 20 5,983 Oct-11-2021, 01:34 AM
Last Post: Underscore
  PYserial basics? bako 10 5,095 Apr-26-2020, 09:15 PM
Last Post: bowlofred
  [split] Debugging scripts basics tultalk 5 3,075 Apr-25-2020, 01:02 AM
Last Post: menator01
  Debugging scripts basics bako 8 3,495 Apr-24-2020, 06:18 AM
Last Post: Larz60+
  Dictionary Basics pythonjm 5 3,504 Nov-26-2018, 11:11 PM
Last Post: pythonjm
  What to do after learning python basics xyzabc12310000 1 2,851 May-20-2018, 11:43 PM
Last Post: micseydel

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020