Skip to content

Commit 35cddec

Browse files
committed
Merge pull request UWPCE-PythonCert#31 from tsegas/master
add lab1 fizzbuzz project
2 parents 6f38549 + d2028a8 commit 35cddec

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

students/tsegas/fbizz_func.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
### lab-1 FizzBizz program: determine if a list of numbers is
2+
### divisible by 3/5/both/niether and print out the results
3+
4+
#FIZZBUZZ function
5+
def fizzbuzz(number):
6+
7+
#if divisible by three or five
8+
dthr = 0
9+
dfiv = 0
10+
11+
# print the number range
12+
print('The numbers to use from 1 to {0} are'.format(number))
13+
14+
for n in range(1,number+1):
15+
# check if numbers are divisible by 3 or 5 or both or niether
16+
if (n % 3) == 0:
17+
dthr = 1
18+
dfiv = 0
19+
if (n % 5) == 0:
20+
dfiv = 1
21+
elif (n % 5) == 0:
22+
dfiv = 1
23+
dthr = 0
24+
else:
25+
print(n)
26+
dthr = 0
27+
dfiv = 0
28+
if (dthr == 1 and dfiv ==0):
29+
print('FIZZ')
30+
if (dthr == 0 and dfiv ==1):
31+
print('BUZZ')
32+
if (dthr == 1 and dfiv ==1):
33+
print('FIZZBUZZ')
34+
#call the function
35+
fizzbuzz(number=30)

0 commit comments

Comments
 (0)