当我按下“运行模块”时,一个shell窗口将打开,没有任何错误,但似乎没有任何运行。我不知道为什么什么也没发生,但是我猜我底部的代码块中的某些代码已经磨损了。游戏是RPS-7或带有7个选项的剪刀石头布。我需要一些故障排除方面的帮助,因为似乎没有问题,但显然存在问题(游戏实际上并未运行,它只是一个无用的外壳)。这是代码,这是我很多人的第一个问题。
import random
def game(choice):
options = ["Rock", "Paper", "Scissors", "Sponge", "Air", "Water", "Fire"]
bot = random.choice(options)
if choice == "Rock" and bot == "Scissors":
print ("Rock crushes scissors, you win!")
elif choice == "Rock" and bot == "Fire":
print ("Rock pounds out fire, you win!")
elif choice == "Rock" and bot == "Sponge":
print ("Rock crushes sponge, you win!")
elif choice == "Rock" and bot == "Paper":
print ("Paper covers rock, you lose..")
elif choice == "Rock" and bot == "Water":
print ("Water erodes rock, you lose..")
elif choice == "Rock" and bot == "Air":
print ("Air erodes rock, you lose..")
elif choice == "Rock" and bot == "Rock":
print ("Rock tries to pound rock but fails, it's a tie!")
elif choice == "Paper" and bot == "Rock":
print ("Paper covers rock, you win!")
elif choice == "Paper" and bot == "Water":
print ("Paper floats on the water, you win!")
elif choice == "Paper" and bot == "Air":
print ("Paper fans the air, you win!")
elif choice == "Paper" and bot == "Scissors":
print ("Paper gets cut by the scissors, you lose..")
elif choice == "Paper" and bot == "Fire":
print ("Paper gets burned by the fire, you lose..")
elif choice == "Paper" and bot == "Sponge":
print ("Paper gets soaked by the sponge, you lose..")
elif choice == "Paper" and bot == "Paper":
print ("Paper tries to cover paper but fails, it's a tie!")
elif choice == "Scissors" and bot == "Paper":
print ("Scissors cuts paper, you win!")
elif choice == "Scissors" and bot == "Air":
print ("Scissors swishes through air, you win!")
elif choice == "Scissors" and bot == "Sponge":
print ("Scissors cuts sponge, you win!")
elif choice == "Scissors" and bot == "Rock":
print ("Scissors gets crushed by rock, you lose..")
elif choice == "Scissors" and bot == "Fire":
print ("Scissors gets melted by scissors, you lose..")
elif choice == "Scissors" and bot == "Water":
print ("Scissors gets eroded by water, you lose..")
elif choice == "Scissors" and bot == "Scissors":
print ("Scissors tries to cut scissors but fails, it's a tie!")
elif choice == "Fire" and bot == "Scissors":
print ("Fire melts scissors, you win!")
elif choice == "Fire" and bot == "Paper":
print ("Fire burns paper, you win!")
elif choice == "Fire" and bot == "Sponge":
print ("Fire burns sponge, you win!")
elif choice == "Fire" and bot == "Rock":
print ("Fire gets pounded out by rock, you lose..")
elif choice == "Fire" and bot == "Air":
print ("Fire gets blown out by air, you lose..")
elif choice == "Fire" and bot == "Water":
print ("Fire gets put out by water, you lose..")
elif choice == "Fire" and bot == "Fire":
print ("Fire tries to burn fire but fails and creates a bigger fire, creating the biggest brushfire known to man. Therefore, it's a tie!")
elif choice == "Sponge" and bot == "Air":
print ("Sponge uses air pockets, you win!")
elif choice == "Sponge" and bot == "Paper":
print ("Sponge soaks paper, you win!")
elif choice == "Sponge" and bot == "Water":
print ("Sponge absorbs water, you win!")
elif choice == "Sponge" and bot == "Rock":
print ("Sponge gets crushed out by rock, you lose..")
elif choice == "Sponge" and bot == "Fire":
print ("Sponge gets burnt by fire, you lose..")
elif choice == "Sponge" and bot == "Scissors":
print ("Sponge gets cut by scissors, you lose..")
elif choice == "Sponge" and bot == "Sponge":
print ("Sponge tries to absorb sponge but fails and solves the world's water problem, however, it's a tie!")
elif choice == "Water" and bot == "Rock":
print ("Water erodes rock, you win!")
elif choice == "Water" and bot == "Fire":
print ("Water puts out fire, you win!")
elif choice == "Water" and bot == "Scissors":
print ("Water rusts scissors, you win!")
elif choice == "Water" and bot == "Sponge":
print ("Water gets absorbed by sponge, you lose..")
elif choice == "Water" and bot == "Air":
print ("Water gets evaporated by air, you lose..")
elif choice == "Water" and bot == "Paper":
print ("Water gets floated on by paper, you lose..")
elif choice == "Water" and bot == "Water":
print ("Water tries to put out water, but fails, creating a large tsunami that wipes out San Francisco. This seems oddly familliar to a song. It's a tie!")
elif choice == "Air" and bot == "Fire":
print ("Air blows out fire, you win!")
elif choice == "Air" and bot == "Rock":
print ("Air erodes rock, you win!")
elif choice == "Air" and bot == "Water":
print ("Air evaporates water, you win!")
elif choice == "Air" and bot == "Paper":
print ("Air gets fanned by paper, you lose..")
elif choice == "Air" and bot == "Scissors":
print ("Scissors swish through air, you lose..")
elif choice == "Air" and bot == "Sponge":
print ("Sponges use air pockets, you lose..")
elif choice == "Air" and bot == "Air":
print ("Air tries to blow out air, fails, and creates a tornado. It's a tie!")
def again(x):
while True:
if x == "y":
game(raw_input("Rock, Paper, Scissors, Sponge, Air, Water, or Fire?"))
again(raw_input("Play RPS - 7 again? y / n."))
else:
print ("Goodbye.")
break
break
game(raw_input("Rock, Paper, Scissors, Sponge, Air, Water, or Fire?"))
again(raw_input("Play RPS - 7 again? y / n."))
运行代码时会发生什么:
答案 0 :(得分:0)
您需要先调用一个函数-现在,您只是在定义函数。添加
again('y')
作为开始循环的文件的最后一行。
答案 1 :(得分:0)
您定义两个函数,然后退出而无需调用它们。您的整个主程序由https://bitbucket.org/rpy2/rpy2/downloads/
语句组成。看来您在底部需要这样的东西:
再次('y')
作为您的主程序。这将一次运行import
函数。