Created
July 29, 2014 20:00
-
-
Save odubno/4ac9a9bf28cd2401600c to your computer and use it in GitHub Desktop.
Fizz Buzz - loops over the user suggested integer the fizz buzz answers
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 | |
#list of strings | |
# assume that a person will only put 1 additional argument | |
# ignore the rest | |
# python Desktop/example_2.py 300 | |
if len(sys.argv) > 1: | |
# user supplied value | |
user_input = sys.argv[1] | |
else: | |
user_input = raw_input("How far do you want to go? (1=?): ") | |
while True: | |
try: | |
user_input = int(user_input) | |
break | |
except: | |
print "That's not a number!" | |
user_input = raw_input("How far do you want to go? (1-?): ") | |
user_range = range(1,user_input+1) | |
for num in user_range: | |
if num % 3 == 0 and num % 5 == 0: | |
print "Fizz Buzz" | |
elif num % 3 == 0: | |
print "Fizz" | |
elif num % 5 == 0: | |
print "Buzz" | |
else: | |
print num | |
"""num = 1 | |
while num < 101: | |
num = num + 1 | |
if num % 3 == 0 and num % 5 == 0: | |
print "Fizz Buzz" | |
elif num % 3 == 0: | |
print "Fizz" | |
elif num % 5 == 0: | |
print "Buzz" | |
else: | |
print num | |
num = num + 1 """ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment