網站首頁 編程語言 正文
?從控制臺輸入要出的拳 —— 剪刀(0)/石頭(1)/布(2)
?電腦 **隨機** 出拳?
?比較勝負
增加錯誤輸入的檢測模塊
# -*- coding = utf-8 -*- # @Time : 22:03 # @Author : huanhuan # @File : test.py # @Software : PyCharm import random def show(num): if num == 0: sign = "剪刀" elif num == 1: sign = "石頭" else: sign = "布" return sign while True: try: com = random.randint(0, 2) people = int(input("請輸入(剪刀:0,石頭:1,布:2):")) if people > 3 or people < 0: print("請輸入正確的數字") else: print("玩家出%s,電腦出%s" % (show(people), show(com))) if (people == 0 and com == 2) \ or (people == 1 and com == 0) \ or (people == 2 and com == 1): print("玩家勝利") elif people == com: print("雙方平局") elif people == 3: print("結束游戲") break else: print("電腦勝利") except ValueError: print("請輸入數字而不是字母")
原文鏈接:https://blog.csdn.net/qq_44771627/article/details/122547894
相關推薦
- 2023-07-14 element組件中的時間選擇器,禁用選擇時間,picker-options屬性詳解,時間選擇器范圍
- 2023-04-08 C#以太網Sockets服務器設計實現_C#教程
- 2023-10-10 微信授權與拒絕授權的彈窗處理
- 2022-10-14 初識RPC中間件zeroC ICE工具之iceca
- 2022-11-23 Android?IdleHandler基本使用及應用案例詳解_Android
- 2022-03-15 更新Android Studio 4.0 啟動模擬器提示 unable to locate adb
- 2022-09-21 Flutter實現資源下載斷點續傳的示例代碼_Android
- 2023-01-07 Python個人博客程序開發實例后臺編寫_python
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支