JINIers
[Python 100 day challenge ] Day 3 - 2 본문
연속되는 여러 if 문
if 안에 if가 또 있음 근데 elif도 있음 ㅜㅜ
쪼꼼 어려웠찌만 뭐.. 나름 해냈더
기특해요 복복복🫳🫳🫳🫳
# multiple if 이용 롤러코스터 키 제한
print("Welcome to the rollercoaster!")
height = int(input("What is your height in cm? "))
bill = 0
if height >= 120:
print("You can ride the rollercoaster!")
age = int(input("What is your age? "))
if age < 12:
bill = 5
print("Child tickets are $5.")
elif age <= 18:
bill = 7
print("Youth tickets are $7.")
elif age >= 45 and age <= 55:
bill = 0
print("Everything is going to be ok. Have a free ride on us!")
else:
bill = 12
print("Adult tickets are $12.")
wants_photo = input("Do you want a photo taken? Y or N. ")
if wants_photo == "Y":
bill += 3
print(f"Your final bill is ${bill}")
else:
print("Sorry, you have to grow taller before you can ride.")
실행결과
키 120 이상일 때
키가 120 미만일 때
# pizza order program
피자 계산기 조건▼
- Small pizza (S): $15
Medium pizza (M): $20
Large pizza (L): $25 - Add pepperoni for small pizza (Y or N): +$2
Add pepperoni for medium or large pizza (Y or N): +$3
Add extra cheese for any size pizza (Y or N): +$1
print("Thank you for choosing 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 ")
bill = 0
if size == "S":
bill += 15
if add_pepperoni == "Y":
bill += 2
else:
extra_cheese
if extra_cheese == "Y":
bill += 1
else:
size
print(f"Your final bill is: ${bill}.")
elif size == "M":
bill += 20
if add_pepperoni == "Y":
bill += 3
else:
extra_cheese
if extra_cheese == "Y":
bill += 1
else:
size
print(f"Your final bill is: ${bill}.")
elif size == "L":
bill += 25
if add_pepperoni == "Y":
bill += 3
else:
extra_cheese
if extra_cheese == "Y":
bill += 1
else:
size
print(f"Your final bill is: ${bill}.")
else:
print(f"Sorry.")
# Love calculator / difficult challenge
이거 약간 무슨말인지 이해 안되서 어려웠는데 이해하고 나니까 재밌었음!
print("The Love Calculator is calculating your score...")
name1 = input("What is your name? ")
name2 = input("What is their name? ")
name = name1 + name2
# name count
t1 = name.lower().count('t')
r1 = name.lower().count('r')
u1 = name.lower().count('u')
e1 = name.lower().count('e')
l1 = name.lower().count('l')
o1 = name.lower().count('o')
v1 = name.lower().count('v')
True_name = t1 + r1 + u1 + e1
Love_name = l1 + o1 + v1 + e1
total = int(str(True_name) + str(Love_name))
if (total < 10) or (total > 90):
print(f"Your score is {total}, you go together like coke and mentos.")
elif (total >= 40) and (total <= 50):
print(f"Your score is {total}, you are alright together.")
else:
print(f"Your score is {total}.")
# Treasure Island
보물찾기
print('''
*******************************************************************************
| | | |
_________|________________.=""_;=.______________|_____________________|_______
| | ,-"_,="" `"=.| |
|___________________|__"=._o`"-._ `"=.______________|___________________
| `"=._o`"=._ _`"=._ |
_________|_____________________:=._o "=._."_.-="'"=.__________________|_______
| | __.--" , ; `"=._o." ,-"""-._ ". |
|___________________|_._" ,. .` ` `` , `"-._"-._ ". '__|___________________
| |o`"=._` , "` `; .". , "-._"-._; ; |
_________|___________| ;`-.o`"=._; ." ` '`."\` . "-._ /_______________|_______
| | |o; `"-.o`"=._`` '` " ,__.--o; |
|___________________|_| ; (#) `-.o `"=.`_.--"_o.-; ;___|___________________
____/______/______/___|o;._ " `".o|o_.--" ;o;____/______/______/____
/______/______/______/_"=._o--._ ; | ; ; ;/______/______/______/_
____/______/______/______/__"=._o--._ ;o|o; _._;o;____/______/______/____
/______/______/______/______/____"=._o._; | ;_.--"o.--"_/______/______/______/_
____/______/______/______/______/_____"=.o|o_.--""___/______/______/______/____
/______/______/______/______/______/______/______/______/______/______/_____ /
*******************************************************************************
''')
print("Welcome to Treasure Island.")
print("Your mission is to find the treasure.")
######################################################
print("Welcome to Treasure Island.")
print("Your mission is to find the treasure.")
choice1 = input("left vs right \n").lower()
if choice1 == "left":
print("살았어! 다음단계로 이동하자!")
choice2 = input("swim or wait \n").lower()
if choice2 == "wait":
print("오, 운이 좋은데? 다음단계로 이동하자!")
choice3 = input("어떤 문으로 들어갈까? red, yellow, blue \n").lower()
if choice3 == "red":
print("이런, 불에 탔어! Game over!! X_X")
elif choice3 == "blue":
print("짐승에게 잡아먹혔어. Game over.")
elif choice3 == "yellow":
print("와!! 보물섬을 찾았다!!")
else:
print("Game over.")
else:
print("상어의 공격을 받았어!! Game Over!!")
else:
print("구멍에 빠져버렸어!! Game Over!! X_X")
실행결과
- 보물찾기 성공
- 보물찾기 실패
코드에 코짜도 적을 줄 몰랐던 내가 3일차에 제법 긴 코드를 써내려가는게 신기하당 ㅋㅋㅋㅋ(뿌듯)
'공부 > Python' 카테고리의 다른 글
[Python 100 day challenge ] Day 5 - for (0) | 2024.03.27 |
---|---|
[Python 100 day challenge ] Day 4 (0) | 2024.03.27 |
[Python 100 day challenge ] Day 3 - 1 (0) | 2024.03.15 |
[Python 100 day challenge ] Day 2 (1) | 2024.03.15 |
[Python 100 day challenge ] Day 1 (0) | 2024.03.15 |
Comments