Q>
"Fizz buzz" is a word game we will use to teach the robots about division.
("Fizz buzz"는 로봇이 분단에 대해 가르치는 단어 게임입니다.)
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;
(숫자가 3과 5로 나눌 수 있다면 "Fizz Buzz";)
"Fizz" if the number is divisible by 3;
(숫자가 3으로 나눌 수있는 경우 'Fizz'; )
"Buzz" if the number is divisible by 5;
(숫자가 5로 나눌 수있는 경우 '버즈 (Buzz)';)
The number as a string for other cases.
(다른 경우의 문자열로 나타낸 숫자입니다.)
Input: A number as an integer.(정수로 나타낸 숫자)
Output: The answer as a string.(답은 문자열입니다.)
Example:
checkio(15) == "Fizz Buzz"
checkio(6) == "Fizz"
checkio(5) == "Buzz"
checkio(7) == "7"
How it is used: Here you can learn how to write the simplest function and work with if-else statements.
(여기서는 가장 간단한 함수를 작성하고 if-else 문을 사용하는 방법을 배울 수 있습니다.)
Precondition: 0 < number ≤ 1000
A>
# Your optional code here
# You can import some modules or create additional functions
def checkio(number: int) -> str:
# Your code here
# It's main function. Don't remove this function
# It's using for auto-testing and must return a result for check.
# replace this for solution
# 숫자를 15로 나누었을때 0이면
if number % 15 == 0:
return 'Fizz Buzz'
# 숫자를 5로 나누었을때 0이면
if number % 5 == 0:
return 'Buzz'
# 숫자를 3로 나누었을때 0이면
if number % 3 == 0:
return 'Fizz'
return str(number)
# Some hints:
# Convert a number in the string with str(n)
# These "asserts" using only for self-checking and not necessary for auto-testing
if __name__ == '__main__':
print('Example:')
print(checkio(15))
assert checkio(15) == "Fizz Buzz", "15 is divisible by 3 and 5"
assert checkio(6) == "Fizz", "6 is divisible by 3"
assert checkio(5) == "Buzz", "5 is divisible by 5"
assert checkio(7) == "7", "7 is not divisible by 3 or 5"
print("Coding complete? Click 'Check' to review your tests and earn cool rewards!")
O>
Example:
[{'name': 'wine', 'price': 138}, {'name': 'bread', 'price': 100}]
Done! Looks like it is fine. Go and check it
Process finished with exit code 0
S>
'Python_Matter > Solve' 카테고리의 다른 글
Python Learn the basics Quiz 48 (0) | 2019.06.10 |
---|---|
Python Learn the basics Quiz 47 (0) | 2019.06.10 |
Python Learn the basics Quiz 45 (0) | 2019.06.10 |
Python Learn the basics Quiz 44 (0) | 2019.06.10 |
Python Learn the basics Quiz 43 (0) | 2019.06.09 |