Skip to content

Instantly share code, notes, and snippets.

@micklskot
Created July 28, 2015 00:36
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save micklskot/6b42d401da715b44ce4d to your computer and use it in GitHub Desktop.
Save micklskot/6b42d401da715b44ce4d to your computer and use it in GitHub Desktop.
# File: fizzbuzz.py
#
# A program based on the game FizzBuzz where a number is checked to see if it
# is....
# Evenly divisible by 3 and 5 which results in 'FizzBuzz'.
# Evenly divisible by 3 which results in 'Fizz'.
# Evenly divisible by 5 which results in 'Buzz'.
# Is not evenly divisible by 3 or 5 which only outputs the number.
for y in range(1,100+1):
if y % 3 == 0 and y % 5 == 0:
print("FizzBuzz")
elif y % 3 == 0:
print("Fizz")
elif y % 5 == 0:
print("Buzz")
else:
print(y)
# File: fizzbuzz_xtra.py
# A program based on the game Fizz Buzz where a number is checked to see if it
# is....
# Evenly divisible by 3 and 5 which results in 'FizzBuzz'.
# Evenly divisible by 3 which results in 'Fizz'.
# Evenly divisible by 5 which results in 'Buzz'.
# Is not evenly divisible by 3 or 5 which only outputs the number.
# This Python program takes integer input from the user at the command line
# after the script name and will also prompt for integer input if not
# initially provided.
import sys
try:
n = int(sys.argv[1])
except (IndexError,ValueError):
while True:
try:
n = int(raw_input("Please enter a number to play the FizzBuzz game... "))
break
except ValueError:
print("Please enter a number to play the FizzBuzz game... ")
print("FizzBuzz is counting up to {}".format(n))
for y in range(1,n+1):
if y % 3 == 0 and y % 5 == 0:
print('FizzBuzz')
elif y % 3 == 0:
print('Fizz')
elif y % 5 == 0:
print('Buzz')
else:
print(y)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment