如何根据用户输入重置代码?

赞纳

我想根据用户输入重置代码,如果是,则重置代码,如果不停止则重置代码。我知道这是一个非常糟糕的代码,很抱歉我还在学习:)

import random

tool = input("Choose your weapon (R)ock (P)aper (S)cissors ")

computer = random.choice(["Rock", "Paper", "Scissors"])

if tool == "R" and computer == "Paper":
    print("You lost aganist ",computer,"!")

elif tool == "R" and computer == "Scissors":
    print("You won aganist! ",computer,"!")

elif tool == "R" and computer == "Rock":
    print("That's a tie!")

elif tool == "P" and computer == "Rock":
    print("You won aganist ",computer,"!")

elif tool == "P" and computer == "Scissors":
    print("You lost aganist ",computer,"!")

elif tool == "P" and computer == "Paper":
    print("That's a tie!")

elif tool == "S" and computer == "Rock":
    print("You lost aganist ",computer,"!")

elif tool == "S" and computer == "Paper":
    print("You won aganist ",computer,"!")

elif tool == "S" and computer == "Scissors":
    print("That's a tie!")
Maritn Ge

将其放在while循环中,并要求重复此操作,如果他拒绝,则将bool设置为no。顺便说一句,这忽略了错误的输入,您应该检查他的输入是否合法,就像我在这里所做的那样

import random

playing = True

while playing:

    tool = input("Choose your weapon (R)ock (P)aper (S)cissors ")

    computer = random.choice(["Rock", "Paper", "Scissors"])

    if tool == "R" and computer == "Paper":
        print("You lost aganist ",computer,"!")

    #...

    elif tool == "S" and computer == "Scissors":
        print("That's a tie!")

    else:
        print("Wrong input! Sorry!")

    play_again = input("Do you want to play again? y/n")
    
    if (play_again == "n"):
        playing = False
        

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

如何根据用户的输入使此代码循环?

来自分类Dev

如何根据用户的输入使此代码循环?

来自分类Dev

您如何根据用户输入运行某个代码块?

来自分类Dev

Shiny和DT:如何根据输入的计算重置输出?

来自分类Dev

如何根据用户输入对列表进行排序?

来自分类Dev

如何根据用户表单输入查询API

来自分类Dev

如何根据用户输入在右侧更新结果

来自分类Dev

如何根据用户输入创建“自动”矩阵?

来自分类Dev

如何根据用户输入创建“自动”矩阵?

来自分类Dev

如何根据用户输入创建“自动”矩阵?

来自分类Dev

如何根据用户输入创建数组?

来自分类Dev

如何根据用户输入生成JButton?

来自分类Dev

如何根据用户输入进行不同的操作

来自分类Dev

如何根据用户输入进行不同的操作

来自分类Dev

如何根据用户输入创建功能?

来自分类Dev

如何根据用户输入进行API调用?

来自分类Dev

如何根据用户输入过滤 div 元素

来自分类Dev

如何根据用户输入创建对象

来自分类Dev

如何根据用户输入删除对象的键?

来自分类Dev

如何根据用户输入从 csv 读取

来自分类Dev

根据用户输入运行代码(Python3,Pandas)

来自分类Dev

CodeIgniter-根据用户输入的字符串生成代码

来自分类Dev

如何在代码上方添加用户输入

来自分类Dev

如何执行作为用户输入的代码?

来自分类Dev

如何让我的代码响应用户输入

来自分类Dev

如何从用户获取输入并根据输入调用函数?

来自分类Dev

根据用户输入以闪亮的方式显示输出表并重置为默认表

来自分类Dev

如何停止用户在文本输入中输入HTML代码

来自分类Dev

如何强制用户不在输入字段中输入代码?

Related 相关文章

热门标签

归档