这是一个基本的游戏,就像石头剪刀布一样,但名称不同,我也为无注释的代码道歉。我的代码快要结束了,但是我在使用 while 循环时遇到了困难。我已经完成了我的所有陈述,但是如何实现一个while循环?我希望游戏在我完成后再次运行,所以它会要求我提供另一个输入。如果我运行它,它正在等待给我一个答案,但从来没有,因为它是一个无限循环。
import random
def pythonRubyJava():
gameList = ["python","ruby","java"]
userInput = raw_input("python, ruby, or java?:")
randomInput = random.choice(gameList)
print randomInput
while True:
if userInput not in gameList:
print "The game is over"
elif userInput == randomInput:
print "stalemate"
elif userInput == "python" and randomInput == "ruby":
print "You win!"
elif userInput == "ruby" and randomInput == "java":
print "You win!"
elif userInput == "java" and randomInput == "python":
print "You win!"
elif userInput == "python" and randomInput == "java":
print "You Lose!"
elif userInput == "ruby" and randomInput == "python":
print "You Lose!"
elif userInput == "java" and randomInput == "ruby":
print "You Lose!"