Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
input issue elif
#1
Code I am writing: Write code that iterates through number 1 - 20 and prints “Fizz” if it’s a multiple of 3, “Buzz” if it’s a multiple of 5, “FizzBuzz” if it’s a multiple of 3 and 5, and the number if it’s not a multiple of 3 or 5. It should only print one statement per number.

x=input ("Please Type a Number from 1 to 20.")
if x%3 == 0 and x%5 == 0:
print ("FizzBuzz")
elif x%3 == 0:
print ("Fizz")
elif x%5 == 0:
print ("Buzz")
else:
print ("Your Number is " + str(x))


My problem - when it executes it is skipping the first three statements and printing Your number is for all numbers.
Reply


Messages In This Thread
input issue elif - by jge047 - Nov-23-2017, 04:52 AM
RE: input issue elif - by cryomick - Nov-23-2017, 06:27 AM
RE: input issue elif - by zykbee - Nov-23-2017, 06:29 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Issue with program not passing to other elif condition Abdirahman 6 3,667 Nov-21-2021, 07:04 AM
Last Post: Abdirahman
Big Grin Newbie to Python - input and branching issue Sherine 3 3,435 Jul-31-2021, 01:09 AM
Last Post: Pedroski55
  Experiencing a bug probably related to input() issue NewtoPython2020 1 2,733 Dec-05-2020, 08:13 AM
Last Post: perfringo
  Using Input() in If...Elif Statements Shemira 11 13,555 Nov-24-2019, 06:57 AM
Last Post: perfringo
  Whats the right way to refactor this Big if/elif/elif ? pitosalas 1 3,012 Jul-28-2019, 05:52 PM
Last Post: ichabod801
  an input error or elif error , how can i fix this the_fire_pharaoh 1 3,051 Dec-15-2018, 09:47 PM
Last Post: Gribouillis
  Mixed string,Integer input variable issue maderdash 2 3,578 Nov-06-2018, 09:46 AM
Last Post: snippsat
  Unexpected input within an if/elif statement fier259 2 3,940 May-12-2018, 07:41 AM
Last Post: buran

Forum Jump:

User Panel Messages

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