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

Python 如何根据用户输入重置代码?,python,Python,我想根据用户输入重置代码,比如如果是,则重置代码如果否,则停止。 我知道这是一个非常糟糕的代码,很抱歉我还在学习:) 把它放在一个while循环中,要求重复它,如果他说不,将bool设置为no。这是忽略错误的输入顺便说一句,你应该检查他的输入是否合法,就像我在这里做的那样 随机导入 玩=真 玩的时候: 工具=输入(“选择您的武器(R)锁(P)纸或缝合器”) 计算机=随机。选择([“石头”,“布”,“剪刀]) 如果工具==“R”和计算机==“纸张”: 打印(“你失去了阿甘主义者”,计算机“!”)

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


把它放在一个while循环中,要求重复它,如果他说不,将bool设置为no。这是忽略错误的输入顺便说一句,你应该检查他的输入是否合法,就像我在这里做的那样

随机导入
玩=真
玩的时候:
工具=输入(“选择您的武器(R)锁(P)纸或缝合器”)
计算机=随机。选择([“石头”,“布”,“剪刀])
如果工具==“R”和计算机==“纸张”:
打印(“你失去了阿甘主义者”,计算机“!”)
#...
elif工具==“S”和计算机==“剪刀”:
打印(“那是一条领带!”)
其他:
打印(“输入错误!对不起!”)
再次播放=输入(“您想再次播放吗?是/否”)
如果(再次播放=“n”):
播放=错误

你的意思是再次重复游戏吗?
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!")