Last active
September 27, 2015 19:52
-
-
Save brooksa321/1ec5b851aef0785a728c to your computer and use it in GitHub Desktop.
Fizz Buzz
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
#Check for command line arguments. If none request argument via user input | |
if len(sys.argv) > 1: | |
n = (sys.argv[1]) | |
else: | |
n = None | |
#Verify user has entered an integer. Will loop until success | |
while True: | |
try: | |
n = int(n) | |
break | |
except TypeError: | |
print "Please enter a whole number" | |
n = (raw_input("What number would you like to play to? ")) | |
except ValueError: | |
print "Incorrect Input. Please enter a whole number" | |
n = (raw_input("What number would you like to play to? ")) | |
y = 0 | |
#FizzBuzz | |
print "Fizz buzz counting up to {}".format(n) | |
while y <= n: | |
if y % 3 == 0 and y % 5 == 0: | |
print"FizzBuzz" | |
elif y % 3 == 0 and y % 5 != 0: | |
print "Fizz" | |
elif y % 3 != 0 and y % 5 == 0: | |
print "Buzz" | |
else: | |
print "{}".format(y) | |
y += 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment