본문 바로가기

Python_Matter/[Check_IO]Elementary

Say Hi

반응형

Quiz>

We have prepared a set of Editor's Choice Solutions. 

You will see them first after you solve the mission.

In order to see all other solutions you should change the filter.

In this mission you should write a function that introduces a person with the given parameter's attributes.

 

Input:

Two arguments. String and positive integer.

 

Output:

String.

 

Example:

say_hi("Alex", 32) == "Hi. My name is Alex and I'm 32 years old"
say_hi("Frank", 68) == "Hi. My name is Frank and I'm 68 years old"

# 1. on CheckiO your solution should be a function

# 2. the function should return the right answer, not print it.

def say_hi(name: str, age: int) -> str:
    """
        Hi!
    """
    # your code here
    return "Hi. My name is Alex and I'm 32 years old"

if __name__ == '__main__':
    #These "asserts" using only for self-checking and not necessary for auto-testing
    assert say_hi("Alex", 32) == "Hi. My name is Alex and I'm 32 years old", "First"
    assert say_hi("Frank", 68) == "Hi. My name is Frank and I'm 68 years old", "Second"
    print('Done. Time to Check.')

 

Solve Case 1>

1. format 함수를 사용하여서 출력 구문을 반환한다.

def say_hi(name: str, age: int):
    return "Hi. My name is {} and I'm {} years old".format(name, age)

 

Solve Case 2>

1. 리터널을 사용하여 출력 구문을 반환 한다.

def say_hi_2(name: str, age: int):
    return f'Hi. My name is {name} and I\'m {age} years old'

 

Code>

def say_hi(name: str, age: int):
    return "Hi. My name is {} and I'm {} years old".format(name, age)

def say_hi_2(name: str, age: int):
    return f'Hi. My name is {name} and I\'m {age} years old'

 

Example>

if __name__ == '__main__':
    # These "asserts" using only for self-checking and not necessary for auto-testing
    assert say_hi(
        "Alex", 32) == "Hi. My name is Alex and I'm 32 years old", "First"
    assert say_hi(
        "Frank", 68) == "Hi. My name is Frank and I'm 68 years old", "Second"
    print('Done. Time to Check.')
    

print(say_hi_2('alex', 32))

 

Result Case 1>

Done. Time to Check.

 

Result Case 2>

Hi. My name is alex and I'm 32 years old

반응형

'Python_Matter > [Check_IO]Elementary' 카테고리의 다른 글

Correct Sentence  (0) 2020.04.11
Fizz Buzz  (0) 2020.04.11
First Word (simplified)  (0) 2020.04.10
Easy Unpack  (0) 2020.04.10
Multiply (Intro)  (0) 2020.04.10