#python #anaconda #jupyter-notebook #visual-code #html #css #javascript #http

제목안녕하세요. Step_05_String.ipynb 연습문제에서 질문이 있습니다.2024-03-22 04:31
작성자

def calcAge(): Step_05_String.ipynb 안에 있는 실습 문제 나이 계산 프로그램 만들기에서  


def calcAge():

    a = input(prompt='Hello, what\'s your name? ')

    x = int(input(prompt='How old are you? '))

    y = int(input(prompt='Years of this year (ex: 2019)? '))

    

    print(a +' is '+ str(x) +' years old.')

    print(a + ' becomes ' + str(x+10) + ' years old after 10 years.')

    print(a + ' becomes ' + str((2097-y)+x) + ' year old in 2098.')


calcAge()


이런 방식으로 코드를 구성하고 실행했을 때 문제에서 원하는 결과를 얻었습니다.

다만 아래 교수님께서 남기신 오류 확인 코드에는 assert calcAge(20, 2019, 2029) == 30 처럼 괄호 안에 값이 부여되어 있습니다. 그러면


a = input(prompt='Hello, what\'s your name? ')

x = int(input(prompt='How old are you? '))

y = int(input(prompt='Years of this year (ex: 2019)? '))

print(a +' is '+ str(x) +' years old.')

print(a + ' becomes ' + str(x+10) + ' years old after 10 years.')

print(a + ' becomes ' + str((2097-y)+x) + ' year old in 2098.')


def calcAge(x,y,z):

    d = (z-y)+x

    return d

    

calcAge(20,2019,2029)


이런 방식으로 코드를 구성하는 것이 맞는지 모르겠습니다.

마찬가지로


def makeBirthdayString():

    a = input(prompt='주민등록번호 앞자리 6자리를 입력해 주세요: ')

    

            

    print('당신의 생일은 '+'19'+a[0:2]+'년 '+a[2:4]+'월 '+a[4]+a[5]+'일 입니다.')

    

makeBirthdayString()


위 코드도 ()형식으로 했는데 오류 확인코드에는 괄호안에 값이 들어 있었습니다.

괄호안에 값을 지정해서 코드를 구성할려면 어떻게 해야될지 궁금힙니다.


댓글