0
출력 결과가 예와 아니오 모두에 대한 인쇄 대답을 생성합니다. 나는 을 생성하고 싶습니다. 사용자가 입력 한대로 대답은 "예"이고 답변은 "아니오"입니다.파이썬 게임이 내가 원하는 것을 출력하지 않습니다.
import time
import random
time.sleep(0)
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("Welcome to the zombie apocalypse simulator!")
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print()
time.sleep(0)
print("You wake up in the backseat of an old 1995 suburu, shirtless and confused.")
time.sleep(0)
print("Looking out the dusty window, you can make out the skyline of a distant")
print("forgotten metropolis.")
print()
time.sleep(0)
def ask(question):
answer = input(question + " {y/n}")
return answer in ['Yes','YES','y', 'Y','yes', 'n', 'N', 'no', 'NO', 'No']
while ask("You see a backpack in the from seat of the car. Do you take it?"):
if ['Yes','YES','y', 'Y','yes']:
print("You look inside only to find a brown hoodie, a utility knife, a can of tuna")
print("and a half full water bottle.")
if ['n', 'N', 'no', 'NO', 'No']:
print("You leave the bag behind.")
break
힌트 : 목록은 '[]'빈 목록이 아닌 한 항상 참입니다. 그러므로''예 ','예 ','y ','Y ','예 ']'가 항상 참일 경우. 'ask()'함수를 고쳐야한다. 왜냐하면'in'은 생각하는 것처럼 작동하지 않기 때문이다. 추신. 코드의 들여 쓰기를 수정하십시오. –
들여 쓰기가 실제로 파이썬에서 중요한 점에 유의하십시오. 실행될 수있는 형식으로 코드를 제시하십시오. –