day 3-7 python (피자주문)
2023. 2. 22. 21:53ㆍ개인적인 공부/Python
Instructions
Congratulations, you've got a job at Python Pizza. Your first job is to build an automatic pizza order program.
Based on a user's order, work out their final bill.
Small Pizza: $15
Medium Pizza: $20
Large Pizza: $25
Pepperoni for Small Pizza: +$2
Pepperoni for Medium or Large Pizza: +$3
Extra cheese for any size pizza: + $1
Example Input
size = "L"
add_pepperoni = "Y"
extra_cheese = "N"
Example Output
Your final bill is: $28.
나의 코드
# 피자 주문
# 🚨 Don't change the code below 👇
print("Welcome to Python Pizza Deliveries!")
size = input("What size pizza do you want? S, M, or L ")
add_pepperoni = input("Do you want pepperoni? Y or N ")
extra_cheese = input("Do you want extra cheese? Y or N ")
# 🚨 Don't change the code above 👆
#Write your code below this line 👇
bill = 0
if size == "S":
bill += 15
if add_pepperoni == "Y":
bill +=2
if extra_cheese == "Y":
bill += 1
print(f"Your final bill is: ${bill}")
elif size == "M":
bill += 20
if add_pepperoni == "Y":
bill += 3
if extra_cheese == "Y":
bill +=1
print(f"Your final bill is: ${bill}")
elif size == "L":
bill += 25
if add_pepperoni == "Y":
bill += 3
if extra_cheese == "Y":
bill +=1
print(f"Your final bill is: ${bill}")
다른스타일
# 다른스타일
if size == "S":
bill +=15
elif size == "M":
bill += 20
else:
bill += 25
if add_pepperoni == "Y":
if size == "S":
bill +=2
else:
bill +=3
if extra_cheese == "Y":
bill +=1
print(f"Your final bill is: ${bill}")
'개인적인 공부 > Python' 카테고리의 다른 글
day 3-9 python 사랑계산기, (Love Calculator) (1) | 2023.02.23 |
---|---|
day 3-8 python (논리 연산자) (0) | 2023.02.22 |
day 3-6 python (다중 연속 if 문) (0) | 2023.02.22 |
day 3-5 python (윤년, Leap Year) (0) | 2023.02.22 |
day 3-4 (BMI 2.0 Exercise) (0) | 2023.02.22 |