python0表示剪刀_简化Python代码(石头、纸、剪刀)

我是一个完全的python新手,这是我在stackoverflow上的第一个问题,所以请耐心等待我:)

所以为了得到一些锻炼,我试着用Python编写我自己的石头,纸,剪刀游戏然而,我的代码相对其他摇滚,纸张,剪刀程序相对较长这是因为我在游戏中编程了所有可能的选项是否有可能简化此代码就像不必在游戏中编程一样因为这样做可能在石头,纸,剪刀,但可能不会在更高级的问题。

让我知道你的想法,谢谢!!!

一切顺利,

卢卡·魏斯贝克

代码:

#Rock, Paper, Scissors

while True:

Game_list = ["Rock", "Paper", "Scissors"]

User_1 = str(input("Rock, Paper, Scissors?"))

#Let the computer make its choice

import random

Computer_1 = random.choice(Game_list)

#Possibility of a draw

if str(Computer_1) == User_1:

Draw_choice = str(input("It's a draw. Do you want to replay?(Y/N)"))

if Draw_choice == "Y":

continue

else:

break

#Possibility of player winning

if str(Computer_1) == "Rock" and User_1 == "Paper" or str(Computer_1) ==

"Paper" and User_1 == "Scissors" or str(Computer_1) == "Scissors" and User_1

== "Rock":

UW1 = str(input("You won. The computer chose:" + Computer_1 + " Do

you want to play again? (Y/N)"))

if UW1 == "Y":

continue

else:

break

#Possibility of computer winning

if str(Computer_1) == "Rock" and User_1 == "Scissors" or str(Computer_1)

== "Paper" and User_1 == "Rock" or str(Computer_1) == "Scissors" and User_1

== "Paper":

UL1 = str(input("You lost. The Compuer chose:" + Computer_1 + " Do

you want to play again? (Y/N)"))

if UL1 == "Y":

continue

else:

break

#End sentence

print("Bye, thank you for playing!")

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值