Skip to content

Commit 94687fa

Browse files
indiranellqxf2
authored andcommitted
Fizzbuzz challenge8 (#11)
* Added new 08_challenge with name_error for Fizzbuzz challenge * Added proper doc strings * Modified the challenge_08 * Changed the obj name from fuzzbuzz to fizzbuzz
1 parent 4e71075 commit 94687fa

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

08_challenge/08_challenge.png

4.58 KB
Loading

08_challenge/08_challenge.py

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
class Fizz_Buzz:
13+
"Class to implement FizzBuzz for multiples of 3 and 5"
14+
15+
def fizzbuzz(max_num):
16+
"This method implements FizzBuzz"
17+
18+
# adding some redundant declarations on purpose
19+
# we will make our script 'tighter' in one of coming exercises
20+
three_mul = 'fizz'
21+
five_mul = 'buzz'
22+
num1 = 3
23+
num2 = 5
24+
25+
# Google for 'range in python' to see what it does
26+
for i in range(1,max_num):
27+
# % or modulo division gives you the remainder
28+
if i%num1==0 and i%num2==0:
29+
print(i,three_mul+five_mul)
30+
elif i%num1==0:
31+
print(i,three_mul)
32+
elif i%num2==0:
33+
print(i,five_mul)
34+
35+
#----START OF SCRIPT
36+
if __name__=='__main__':
37+
"Initialize the fizzbuzz object"
38+
fizzbuzz_obj = Fizz_Buzz()
39+
fizzbuzz_obj.fizzbuzz(100)
40+

08_challenge/08_name_error.png

4.14 KB
Loading

08_challenge/08_readme.md

Whitespace-only changes.

0 commit comments

Comments
 (0)