Angela 박사의 100일 간의 코드 Python 부트캠프 중 02일

Day 02에서는 데이터 유형, 수학 연산 및 f 문자열 사용을 다루는 팁 계산기를 만들었습니다.

#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

print("Welcome to the tip calculator!")
#Get Total bill
total_bill = float(input("What was the total bill? $"))
#Get how many percentage for the bill
tip = int(input("How much tip would you like to give? 10, 12, or 
15? "))
#Get how many persons to split the bill
bill_split_person = int(input("How many people to split the bill? "))

#Get Percentage of tip for total bill and add the value of tip to 
total bill / each person
calc_bill = round((total_bill * float(tip/100) + total_bill) / 
bill_split_person, 2)
final_bill = "{:.2f}".format(calc_bill)
print(f"Each person should pay: ${final_bill}")



산출:

좋은 웹페이지 즐겨찾기