티스토리 뷰

Programming/Python

Day 2 . Data type , f -string , Round

우주아줌마 2022. 8. 2. 23:57
728x90
반응형

Day 2. 문제

Instructions

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

Thus everyone's share of the total bill is $30.00 plus a $3.60 tip.

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

Example Input

Welcome to the tip calculator!
What was the total bill? $124.56
How much tip would you like to give? 10, 12, or 15? 12
How many people to split the bill? 7

Example Output

Each person should pay: $19.93

 


위 문제를 풀어야 하는데.....

print("Welcome to the tip calculator!")
bill = input("What was the total bill ?")
float(bill)
tip = input("How much tip would you like to give? 10, 12, or 15? ")
int(tip)
people = input("How may people to split the bill? ")
int(people)
total = ((bill / people ) * round(tip,2))
print(f"Each person should pay: ${total}")

내가 풀다 오류 나서 못 풀었다...

아 2일 차부터 헤딩하면 답 없는데... 

힌트도 영어고.. 힘들다

 Error 

이거 에러 메시지도 복사가 안돼서 일일이 타이핑해야 할 판이다...
그냥 답을 볼가 하다가 에러를 검색해보기로 했다..

stackoverflow.com 검색결과

input  함수 앞에 int , float를 주어서 입력값 자체를 형 변환하고 변수에 넣으라는 거 봤다

근데.... 이거 수업 앞부분에서 했던 거 같다.... 역시 나는 돌대가리다...

바로 적용 후

에러는 해결 됐는데 결과 값이 개판이다...

소수점 뒤에 자를 아는데 그리고... 예제에서 124.56에 12% , 7명 하면 19.93 이 나와야 하는데

이거 뭔가 미친 거다... 산수.... 어렵다 산수.. 프로그래밍 2일 차에 이런 난제를.... 난 프로그램으로 성공은 못할 거다..

 

결국 23:47이라 더 이상 끌면 내일 출근도 힘들고 술기운도 올라와서 이제 그냥 정답을 봐버렸다

산수가 문제다 산수.... 아..... 곱하기 나누기도 못하는 42살이라니...  이거 프로그램 공부할게 아니라...

산수부터 공부해야겠다.

정답은

# Practice
print("Welcome to the tip calculator!")
bill = float(input("What was the total bill? $"))
tip = int(input("How much tip would you like to give? 10, 12, or 15? "))
people = int(input("How may people to split the bill? "))

tip_as_percent = tip / 100
total_tip_amount = bill * tip_as_percent
total_bill = bill + total_tip_amount
bill_per_person = total_bill / people
total = round(bill_per_person,2)
print(f"Each person should pay: ${total}")

round 함수 말고도 다른 방식이 있다

8월3일 4분전 ... 내일 지각 하지 않기 위해서 오늘은 여기 까지.. 아... 영어 공부 못했내..

술을 끊던가 해야지 진짜...

술 끊자!


 

728x90
반응형
댓글