그래서 저는 자신의 모험 게임을 선택하여 파이썬을 배우려고합니다. 내가 만나는 문제는 사용자가 실제로 선택할 수 없다는 것입니다. 나는 많은 내용을 썼다. 사용자가 홀 1 또는 홀 2 사이를 선택하도록하고 싶다.하지만 지금 사용자가 1 또는 2를 타이핑하면 아무 일도 일어나지 않는다. 그냥 빈 줄에 가서 구멍 1/2 내용을 제공하지 않습니다. 나는 사용자 입력을 저장하고 나서 다시 불러들이는 데 문제가 있다고 생각하지만 해결 방법을 모르겠습니다. 이상적으로 사용자가 1 또는 2를 입력하면 해당 구멍에 상황이 표시됩니다. 나는 초보자라는 것을 지적하고 싶다. 더 좋은 방법이나 더 효율적인 방법을 써야 겠지만 내 주된 관심사는 플레이어를 홀 1 또는 홀 2로 만드는 것이다. 파이썬을 사용하고있다. 스파이더 3.x의 3.6.if/else python 3.4
def main():
print('A giant ship comes crashing down in your swamp and ruins your possum and larvae soup.')
print('A man emerges from the swamp. Gross he says. Why would anyone live in this shithole swamp?')
print('Yoda emerges from his hut. I live here. I am Yoda, the talking swamp rat that will teach you how to kill your father.')
begin = input("Do you want my help? Q=Quit. ")
if begin.lower() !='q':
print('Good lets begin') ##!='q': this is how you give someone the option to quit.
else:
print('good luck im going to eat some larvae and possum soup')
userName = input("I have to ask. What is your name? ")
print('Nice to meet you', userName,'Skywalker')
print('Okay so first things first, lets get your ship out of my swamp. Great', userName, 'says.')
print('But I will only do it if you catch me some possums. They are a delicassy here. They are in one of those 2 holes.')
holeInput = input('Do you want to go into hole one or hole two? type one/two ')
if holeInput == one: ##why won't this work?
print('You enter the hole. It is small and you have to crawl. All of a sudden there is a bright light.')
print('You see a family of squirrels. Squirrels are not possums.')
squirrel = input("Do you bring the squirrel to Yoda and hope he does not notice or do you leave? Quit means leave. Q=Quit.")
if squirrel.lower() !='q':
print('Congrats! you are now fighting a squirrel. You kill the squirrel in one blow and bring its carcass to Yoda.')
print('You are a liar! Yoda says. I will not help you. Yoda goes inside and eats some possum and larvae soup.')
return holeInput
else:
print('You leave the hole to check the other hole.')
return holeInput
else:
return holeInput
if holeInput == two:
print('You enter the hole. It is small and you have to crawl. All of a sudden there is a bright light.')
print('You see a family of possums reading the space bible. One of the possums has glasses and a human face.')
print('The possum turns to you. I am not a possum he says. My name is George Lucas the possum says. But it could be a lie. He really looks like a possum.')
lucas = input("Do you listen to the talking possum? Quit means let him live. Q=Quit.")
if lucas.lower() !='q':
print('You kill the possum in one blow. You bring his body to Yoda. Wow! thats the biggest possum I have ever seen. You are a good guy and I will help you Yoda says.')
else:
print('You leave. Yoda calls you a failure.')
return holeInput
main()
소스 코드에서'1'은 int를 나타냅니다. 'input'은 항상 문자열을줍니다. – user2357112
'one'은 변수입니다. ''one''은 비교할 문자열입니다. 큰 차이는'one! = "one"이라고 가정합니다. –
@ user2357112 holeInput = int (입력 ('구멍 하나 또는 구멍 2에 들어가시겠습니까? 1/2을 입력하십시오))로 변경하고 효과가있었습니다. 감사! – amnmustafa15