Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
chatbot-final/fz.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
23 lines (22 sloc)
690 Bytes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fizzbuzz(x): | |
if x%3 == 0 and x%5 == 0: | |
return "fizzbuzz" | |
elif x%3 == 0: | |
return "fizz" | |
elif x%5 == 0: | |
return "buzz" | |
else: | |
return str(x) | |
def starter(): | |
fizz_list = [fizzbuzz(k) for k in range(1, 31)] | |
print('''Welcome to FizzBuzz. Start counting from 1 all the way to 30. | |
The rules are simple: | |
if the number is divisible by 3, enter 'fizz', | |
if it's divisible by 5, enter 'buzz', | |
if it's divisible by 3 and 5, enter 'fizzbuzz'.''') | |
for i in range(len(fizz_list)): | |
x = input("Enter your answer: ") | |
if not (x == fizz_list[i]): | |
print("You failed, the answer was",fizz_list[i]) | |
quit() | |
starter() |