저는이 파이썬 코드를 약 한 시간 동안 작동 시키려고 노력해 왔지만 그것을 고칠 수는 없습니다. 전에 파이썬에 들어갔다. 그렇다면 이것이 쉬운 이유가 바로 그 이유이다. 파이썬 텍스트 어드벤처 게임이 작동하지 않습니다.
def firstChoice():
time.sleep(2)
print('You come across a path, it splits at the end.')
time.sleep(1)
choice=input('Which path do you take, the left path (1) or the right path (2)? \n')
checkChoice()
def checkChoice():
# correct
if choice=='1' or choice=='2':
correct_choice=randint(1,2)
if choice==correct_choice:
correct=True
if choice!='1' or choice!='2':
print('You decide to not take a path, and you die due to random circumstances.')
time.sleep(1)
print('Take a path next time, or at least take it correctly.')
failScreen()
I've imported everything necessary (time and random)
EDIT: Here's the whole code.
import random
import time
choice=0
def introDisplay():
print('This is the pre-game story.')
time.sleep(1)
print('It lasts for 5 lines.')
time.sleep(1)
print('When you can be arsed, fix this.')
time.sleep(1)
print('Thanks,')
time.sleep(1)
print('You, from 18/3/17')
print()
firstChoice()
def firstChoice():
time.sleep(2)
print('You come across a path, it splits at the end.')
time.sleep(1)
choice=input('Which path do you take, the left path (1) or the right path (2)? \n')
checkChoice(choice)
def checkChoice(choice):
correct=False
if choice=='1' or choice=='2':
correct_choice=random.randint(1,2)
if choice==correct_choice:
correct=True
if choice!='1' and choice!='2':
print('You decide to not take a path, and you die due to random circumstances.')
time.sleep(1)
print('Take a path next time, or at least take it correctly.')
failScreen()
def failScreen():
restart=True
print('You have failed.')
print('Do you want to retry?')
restart1=input('Y or y = Yes. N or n = No. \n')
if restart1=='y' or restart1=='Y':
restart=True
if restart1=='n' or restart1=='N':
restart=False
if restart1!='n' or restart!='N' or restart!='y' or restart!='Y':
failScreen()
if restart==True:
introDisplay()
if restart==False:
exit()
introDisplay()
'데프 checkChoice (선택) :'그리고 당신이 그것을'checkChoice (choice)'라고 부를 때. –
작동하지 않는 경우에도 두 번째에 'else'를 사용해야합니다 ... – MobyCoding
사이트 규칙에 따라 더 나은 (답변 할 수있는) 질문을 작성하는 방법은 http://stackoverflow.com/help/mcve를 참조하십시오. . 또한 http://stackoverflow.com/help/how-to-ask를 참고하십시오. 문제가 발생할 때 어떤 종류의 프로그램을 쓰는 것이 아닌, 문제 자체를 신경 써야합니다. 같은 문제가있는 ** 가능한 가장 짧은 프로그램 ** - 가장 짧은 프로그램은 아마도 텍스트 모험이 아닐 것입니다. 귀하의 질문이 귀하가 작성한 프로그램에 초점을 맞춘 것이지 문제가 아니라 잘못된 장소에 집중되어 있습니다. –