Skip to content

Instantly share code, notes, and snippets.

@SahilKadam
Created October 15, 2016 00:10
Show Gist options
  • Save SahilKadam/72755e1465755a20b03c1db141c98a19 to your computer and use it in GitHub Desktop.
Save SahilKadam/72755e1465755a20b03c1db141c98a19 to your computer and use it in GitHub Desktop.
Write a program that, given a number n from STDIN, prints out all numbers from 1 to n (inclusive) to STDOUT, each on their own line. But there's a catch: For numbers divisible by 3, instead of n, print Fizz For numbers divisible by 5, instead of n, print Buzz For numbers divisible by 3 and 5, just print FizzBuzz
n = int(input().strip())
for i in range(1,n+1):
if i%3 == 0 and i%5 == 0:
print ("FizzBuzz")
elif i % 3 == 0:
print ("Fizz")
elif i % 5 == 0:
print ("Buzz")
else:
print (i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment