카테고리 없음

[파이썬연습] DAY 2.3 파이썬의 숫자 처리 및 F - string

슬로우코더 2022. 11. 28. 11:29

기초로 배운 것

반올림 round()

 

소수점 버리기 // 8//3 

 

+= -=

 

f-String

연습문제

사용자에게 나이를 입력하게 해서

90살까지 산다는걸로 가정하여

여생을 일, 주, 월 로 출력한다.

 

F- string을 사용해야 할듯 

내가 한 코딩

# 🚨 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 👇

day = (90-int(age))*365
week = (90-int(age))*52 
month = (90-int(age))*12

result = f"You have {day} days, {week} weeks and {month} months left."
print(result)

모범답안

# 🚨 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 👇

years = 90 - int(age)
months = round(years * 12)
weeks = round(years * 52)
days = round(years * 365)

print(f"You have {days} days, {weeks} weeks, and {months} months left.")

 

사용 명령어

f string

round

총평

문자열 정수형 소수형이 좀 헷갈린다.

 

udemy의 파이썬 강좌를 보고 연습하는 공간입니다.
문제가 될 시 삭제하겠습니다.
udemy 파이썬 강좌 -> https://www.udemy.com/course/best-100-days-python