import random
def pythonrubyjava():
gamelist = ["python" , "ruby", "java"]
userinput = raw_input("python, ruby, or java?:")
randominput = random.choice(gamelist)
print randominput
if userinput not in gamelist:
print "The game is over"
elif userinput == randominput:
print "correct"
elif userinput == "python" and randominput == "ruby":
print "WINNER!"
elif userinput == "ruby" and randominput == "java":
print "WINNER!"
elif userinput == "java" and randominput == "python":
print "WINNER!"
elif userinput == "python" and randominput == "java":
print "loser..."
elif userinput == "ruby" and randominput == "python":
print "loser..."
elif userinput == "java" and randominput == "ruby":
print "loser..."
这是我到目前为止所做的,但它要么说执行命令而且永远不会完成或者没有返回正确的东西。
答案 0 :(得分:4)
放一个main函数然后执行它:
if __name__=="__main__":
pythonrubyjava()