Skip to content
This repository has been archived by the owner on Aug 29, 2020. It is now read-only.

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
carpben committed Jul 26, 2015
0 parents commit e7aa610
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Empty file added README.md
Empty file.
39 changes: 39 additions & 0 deletions fizzbuzz.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import sys

print "Welcome to the Fizzbuzz Game!"

# defining n.
# first option command line argument. command line can have: 1 argument (no n), 2 arguments (n) or more than 2 arguments (mistake/error)
# In case of 2 arguments, the second argument is n. otherwise n will be equal to user's input.
#possible problems: argument or input should be an integer in type string. If that is not the case than we have a problem.
# we are instructed to handel error.
# it will arise when we try to convert from type string to type integer.
if len(sys.argv)==2:
n=sys.argv[1]
else: #This will execute if the user provide n, or provided more than 2 arguments.
n=raw_input ("Please enter a number. We will play Fizzbuzz up to the number you choose. ")
while True:
try:
n=int(n)
break
except Exception, e:
#while (type(n)==int)==False:
n=raw_input ("Please enter a number. We will play Fizzbuzz up to the number you choose. ")
#try:
# n=int(n)
# except Exception, e:
# pass

# printing fizzbuzz up to n
print "Fizz buzz counting up to {}".format (n)
for num in range (1,n+1):
if (num%5==0) & (num%3==0):
print("Fizzbuzz")
elif num%5==0:
print("Buzz")
elif num%3==0:
print("Fizz")
else:
print(num)


0 comments on commit e7aa610

Please sign in to comment.