This repository has been archived by the owner on Aug 29, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit e7aa610
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains 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
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) | ||
|
||
|