[Python] Checkio Solution 解答 – Fizz Buzz

架網編程

Problem:

"Fizz buzz" is a word game we will use to teach the robots about division. Let's learn computers.

You should write a function that will receive a positive integer and return:
"Fizz Buzz" if the number is divisible by 3 and by 5;
"Fizz" if the number is divisible by 3;
"Buzz" if the number is divisible by 5;
The number as a string for other cases.

 

Level:

Elementary

 

Input:

A number as an integer.

 

Output:

The answer as a string.

 

Precondition:

0 < number ≤ 1000

 

Source: https://py.checkio.org


My Solution:

def checkio(number): 
  if number % 3 == 0 and number % 5 == 0: 
    reply = "Fizz Buzz" 
  elif number % 3 == 0: 
    reply = "Fizz" 
  elif number % 5 == 0: 
    reply = "Buzz" 
  else: 
    reply = str(number) 
  return reply

Comment:

This problem is just like what you can solve when you learn your Python on Codecademy.

發佈日期:2017年9月13日 | 作者:橘小佑

Copyright © Vantopics