Python: 삶을 week 단위로 나타내기

Frigate·2022년 5월 22일
0

Python 기초문법

목록 보기
17/27

학습목표:나이를 입력하면 남은 햇수를 주 단위로 출력해보기
참고자료: https://replit.com/@appbrewery/day-2-3-exercise / https://waitbutwhy.com/2014/05/life-weeks.html

Instructions

인간이 90세까지 운좋게 살 수 있다면, 실제로 몇일 몇주 몇달 남았는지 알려주는 프로그램을 만드시오

  • 1년은 365일, 52주, 12개월로 나타낼 수 있음
You have x days, y weeks, and z months left.  # 이런 포맷으로 실행결과가 되어야 함.

Example Input

56

Example Output

You have 12410 days, 1768 weeks, and 408 months left.

Try it!
1. 오답. print()는 서로 다른 데이터형을 한번에 출력 불가

*concatenate : 결합하기

*input()함수로 저장한 데이터는 str타입이다!

# 🚨 Don't change the code below 👇
age = input("What is your current age?")
# 🚨 Don't change the code above 👆

#Write your code below this line 👇
left_years = 90 - int(age)
left_days = left_years * 365
left_weeks = left_years * 52
left_months = left_years * 12
print("You have " + left_days + " days, " + left_weeks + " weeks",  + "and " + left_months + " months left.")
  1. 정답
# 🚨 Don't change the code below 👇
age = input("What is your current age?")
# 🚨 Don't change the code above 👆

#Write your code below this line 👇
left_years = 90 - int(age)
left_days = left_years * 365
left_weeks = left_years * 52
left_months = left_years * 12
print("You have " + str(left_days) + " days, " + str(left_weeks) + " weeks, " + "and " + str(left_months) + " months left.")

#실행결과: what is your current age?25
              You have 23725 days, 3380 weeks, and 780 months left.

#유데미 #유데미코리아 #스타트위드유데미 #스터디윗미

profile
Swift

0개의 댓글