-
Notifications
You must be signed in to change notification settings - Fork 216
Expand file tree
/
Copy path08_challenge.py
More file actions
40 lines (33 loc) · 1.18 KB
/
08_challenge.py
File metadata and controls
40 lines (33 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
"""
We will use this script to teach Python to absolute beginners
The script is an example of Fizz-Buzz implemented in Python
The FizzBuzz problem:
For all integers between 1 and 99 (include both):
# print fizz for multiples of 3
# print buzz for multiples of 5
# print fizzbuzz for multiples of 3 and 5"
"""
class Fizz_Buzz:
"Class to implement FizzBuzz for multiples of 3 and 5"
def fizzbuzz(self,max_num):
"This method implements FizzBuzz"
# adding some redundant declarations on purpose
# we will make our script 'tighter' in one of coming exercises
three_mul = 'fizz'
five_mul = 'buzz'
num1 = 3
num2 = 5
# Google for 'range in python' to see what it does
for i in range(1,max_num):
# % or modulo division gives you the remainder
if i%num1==0 and i%num2==0:
print(i,three_mul+five_mul)
elif i%num1==0:
print(i,three_mul)
elif i%num2==0:
print(i,five_mul)
#----START OF SCRIPT
if __name__=='__main__':
"Initialize the fizzbuzz object"
new_object = Fizz_Buzz()
new_object.fizzbuzz(345)