1 분 소요

파이썬 프로젝트 2

오늘도 알찬 하루였다. 따라가기 벅차기도 했지만, 내가 짠 코드로 프로그램을 돌리는 과정에서 성취감을 크게 느끼는 것 같다. 점점 실력이 늘고 있는 것 같다.

남은 수명 계산기

# 🚨 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 = 365 * 90
week = 52 * 90
month = 12 * 90

age_day = int(age) * 365
age_week = int(age) * 52
age_month = int(age) * 12

print(f"You have {day - age_day} days, {week - age_week} weeks, and {month - age_month} months left. ")

#print(f"You have 12410 days", "1768 weeks", "and 408 months left.")

운이 좋게 90살까지 산다고 가정할 때, 현재 내 나이를 입력하여 수명을 계산하는 것이다.

팁 계산기

#If the bill was $150.00, split between 5 people, with 12% tip. 

#Each person should pay (150.00 / 5) * 1.12 = 33.6
#Format the result to 2 decimal places = 33.60

#Tip: There are 2 ways to round a number. You might have to do some Googling to solve this.💪

#Write your code below this line 👇

print                   ("Welcome to the tip calculator!")
totall_bill     =  input("What was the total bill? $")
How_much_tip    = input("How much tip would you like to give? 10, 12, or 15? ")
How_many_people = input("How many people to split the bill? ")

bill  = float(totall_bill)
c_tip = int(How_much_tip) * 0.01
people = int(How_many_people) 

percentage = bill * c_tip
last_percentage = bill + percentage

last_tip = last_percentage / people
tip = round(last_tip, 2)


print(f"Each person should pay: ${tip}")

식당에 갔을 때 내야할 팁을 계산하는 팁 계산기 이다. 변수를 여러개 넣어서 알아보기 쉽게 클린 코딩하려고 해보았다.

오늘 배운 함수

float, round, int, str. 

TOSS 후원 카카오페이 후원

댓글남기기