File tree Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Expand file tree Collapse file tree 3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change
1
+ """
2
+ We will use this script to teach Python to absolute beginners
3
+ The script is an example of Fizz-Buzz implemented in Python
4
+
5
+ The FizzBuzz problem:
6
+ For all integers between 1 and 99 (include both):
7
+ # print fizz for multiples of 3
8
+ # print buzz for multiples of 5
9
+ # print fizzbuzz for multiples of 3 and 5"
10
+ """
11
+
12
+ def fizzbuzz (max_num ):
13
+ "This method implements FizzBuzz"
14
+
15
+ # adding some redundant declarations on purpose
16
+ # we will make our script 'tighter' in one of coming exercises
17
+ three_mul = 'fizz'
18
+ five_mul = 'buzz'
19
+ num1 = 3
20
+ num2 = 5
21
+
22
+ # Google for 'range in python' to see what it does
23
+ for i in range (1 ,max_num ):
24
+ # % or modulo division gives you the remainder
25
+ if i % num1 == 0 and i % num2 == 0 :
26
+ print (i ,three_mul + five_mul )
27
+ elif i % num1 == 0 :
28
+ print (i ,three_mul )
29
+ elif i % num2 == 0 :
30
+ print (i ,five_mul )
31
+
32
+ #----START OF SCRIPT
33
+ if __name__ == '__main__' :
34
+ fizzbuzz (99 )
You can’t perform that action at this time.
0 commit comments