Skip to content

Commit

Permalink
Merge pull request #3 from rajiqxf2/challenge12
Browse files Browse the repository at this point in the history
fizzbuzz into a class and values are initialized in init

Looks good @rajiqxf2 
I read the code and checked the image. Both seem easy enough for me to follow.
  • Loading branch information
qxf2 authored Oct 23, 2018
2 parents 9007d33 + 7614718 commit 096fa7c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions 12_challenge/12_challenge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
"""
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 FizzBuzz():

def __init__(self):
"Initializer"
# adding some redundant declarations on purpose
# we will make our script 'tighter' in one of coming exercises
self.num1 = 3
self.num2 = 4
self.three_mul = 'fizz'
self.five_mul = 'buzz'


def fizzbuzz(self,max_num):
"This method implements FizzBuzz"

# 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%self.num1==0 and i%self.num2==0:
print(i,self.three_mul+self.five_mul)
elif i%self.num1==0:
print(i,self.three_mul)
elif i%self.num2==0:
print(i,self.five_mul)

#----START OF SCRIPT
if __name__=='__main__':
#Testing the fizzbuzz class
test_obj = FizzBuzz()
test_obj.fizzbuzz(100)
Binary file added 12_challenge/12_no_buzz_for_5_muls.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Empty file added 12_challenge/12_readme.md
Empty file.

0 comments on commit 096fa7c

Please sign in to comment.