我创建了一个混乱的文字游戏,它进入了无限循环,无法从循环中退出。 我无法获得并在感谢定义上打印。 无法退出。 无法从循环中来。 m找不到缩进错误。 但是游戏一直在问玩家同样的问题没有结束。 我正在使用spyder IDE python 3.7。
import random
def choose():
words=["computer","laptop","communication","electronics","science"]
pick=random.choice(words)
return pick
def jumble(word):
j_word="".join(random.sample(word,len(word)))
return j_word
def thank(p1n,p2n,p1,p2):
print(p1n,"your score is: ",p1)
print(p2n,"your score is: ",p2)
print("thanks for playing.have a nice day")
def play():
p1name=input("player 1: enter your name")
p2name=input("player 2: enter your name")
pp1=0
pp2=0
turn=0
while(1):
picked_word=choose()
ques=jumble(picked_word)
print(ques)
if(turn%2==0):
print(p1name," your turn ")
ans= input("what is the answer ")
if ans==picked_word:
pp1=pp1+1
print("player1 : your score is ",pp1 )
else:
print("better luck next time.. the word was ",picked_word)
game=input("continue or not 1/0 ")
if(game==0):
c=thank(p1name,p2name,pp1,pp2)
break
else:
print(p2name," your turn ")
ans= input("what is the answer ")
if ans==picked_word:
pp2=pp2+1
print("player2 : your score is",pp2 )
else:
print("better luck next time.. the word was",picked_word)
game=input("continue or not 1/0 ")
if(game==0):
c=thank(p1name,p2name,pp1,pp2)
break
turn=turn+1
play()