如何用PYTHON制作剪刀石头布游戏

 时间:2024-10-30 22:39:12

1、打开PYTHON,新建一个空白的PYTHON文档。

如何用PYTHON制作剪刀石头布游戏

3、player1 = input("Please select your way to win: ")player2 = input("Please select your way to win: ")if player1 == "rock" and player2 == "scissors": print("The winner is player1")elif player1 == "scissors" and player2 == "paper": print("The winner is player1")elif player1 == "paper" and player2 == "rock": print("The winner is player1")换了另一个输入就可以看出有问题了。

如何用PYTHON制作剪刀石头布游戏

5、rules = {"rock": {"scissors": "wins", "paper": "loses"}, "scissors": {"rock": "loses", "paper": "wins"}, "paper": {"rock": "wins", "scissors": "loses"}}player1 = input("Please select your way to win: ")player2 = input("Please select your way to win: ")print("The player1 " + rules[player1][player2])我们也可以用字典来定义规则,字典里面还可以添加字典,这样直接导出结果。

如何用PYTHON制作剪刀石头布游戏

7、import ran蟠校盯昂domplayer1 = input("Please select your way to win: ")def who_wins(choice): options = ["rock", "scissors", "paper"] player2 = random.choice(options) print("player2 is using {}.".format(player2)) if player1 == "rock": if player2 == "scissors": print("The winner is player1") else: print("The winner is player2") elif player1 == "scissors": if player2 == "rock": print("The winner is player2") else: print("The winner is player1") elif player1 == "paper": if player2 == "rock": print("The winner is player1") else: print("The winner is player2") elif player1 == player2: return("Draw") who_wins(player1)我们还可以用RANDOM来随机玩家输入的选项,这样会更加有趣。

如何用PYTHON制作剪刀石头布游戏
  • Python编程:怎么将元组对象转换为json字符串
  • ipconfig命令的使用方法
  • 【校园指南】云南大学呈贡校区上网攻略
  • 百词斩如何获得铜板?
  • wamp怎么进入mysql的命令行界面?
  • 热门搜索
    一个手机号可以注册几个微信 可以提现的棋牌游戏 九寨沟旅游网 吃什么可以增加免疫力 什么植物可以净化空气 我可以无限升级 阴囊潮湿瘙痒怎么办 颈部淋巴结肿大怎么治疗 凉拌藕片的做法 长沙商贸旅游职业技术学院