Python石头剪刀游戏没有任何输出

2024-04-19 05:10:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我一按“Run Module”,一个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."))

运行代码时会发生什么:

This


Tags: andyoubotairwinfirepaperprint
2条回答

你需要先调用一个函数-现在,你只是在定义函数。添加

again('y')

作为启动循环的文件的最后一行

您定义了两个函数,然后在没有调用它们的情况下退出。整个主程序由import语句组成。在底部似乎需要这样的东西:

再次('y')

作为你的主要节目。这将运行again函数一次

相关问题 更多 >