fizzbuzzforkicks
This commit is contained in:
parent
49627606f7
commit
d8ef3476f2
1 changed files with 41 additions and 0 deletions
41
fizzbuzz.py
Normal file
41
fizzbuzz.py
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
# This is a really dumb idea this code is gonna be shit
|
||||||
|
|
||||||
|
import sys
|
||||||
|
|
||||||
|
def parse_command_line(argv):
|
||||||
|
if(len(argv) == 1):
|
||||||
|
print('Default value: 5')
|
||||||
|
return 100
|
||||||
|
|
||||||
|
elif(len(argv) > 2):
|
||||||
|
print('Too many arguments!')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
num = int(argv[1])
|
||||||
|
return num
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(str(e))
|
||||||
|
print('Non-integer input.')
|
||||||
|
return 0
|
||||||
|
|
||||||
|
return int(argv[1])
|
||||||
|
|
||||||
|
def fizzbuzz(n):
|
||||||
|
for i in range(1, n + 1):
|
||||||
|
output = ''
|
||||||
|
if(i%3 == 0):
|
||||||
|
output += 'Fizz'
|
||||||
|
if(i%5 == 0):
|
||||||
|
output += 'Buzz'
|
||||||
|
if(output == ''):
|
||||||
|
output = str(i)
|
||||||
|
print(output)
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
num = parse_command_line(argv)
|
||||||
|
fizzbuzz(num)
|
||||||
|
|
||||||
|
main(sys.argv)
|
Reference in a new issue