File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change 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 )
You can’t perform that action at this time.
0 commit comments