mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
Create Solution_BuzzFizz.py
Test Cases * None -> Exception * < 1 -> Exception * 15 -> [ '1', '2', 'Fizz', '4', 'Buzz', 'Fizz', '7', '8', 'Fizz', 'Buzz', '11', 'Fizz', '13', '14', 'FizzBuzz' ]
This commit is contained in:
parent
ba3ec6f492
commit
975abd11c6
22
arrays_strings/fizz_buzz/Solution_BuzzFizz.py
Normal file
22
arrays_strings/fizz_buzz/Solution_BuzzFizz.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
class Stringassign:
|
||||
def change_number(self,upto_numbers):
|
||||
if upto_numbers < 0:
|
||||
print ("Exception")
|
||||
for no in range(1,upto_numbers):
|
||||
if no%3==0 and no%5==0:
|
||||
print("FizzBuzz")
|
||||
continue
|
||||
elif(no%3)==0:
|
||||
print("Fizz")
|
||||
continue
|
||||
elif(no%5)==0:
|
||||
print("Buzz")
|
||||
continue
|
||||
print (no)
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
upto_numbers=input("upto which number you want to print...?\t")
|
||||
change_instance=Stringassign()
|
||||
change_instance.change_number(int(upto_numbers))
|
||||
except ValueError:
|
||||
print("Exception")
|
Loading…
Reference in New Issue
Block a user