網站首頁 編程語言 正文
?從控制臺輸入要出的拳 —— 剪刀(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
相關推薦
- 2022-10-03 React中路由參數如何改變頁面不刷新數據的情況_React
- 2022-11-04 Android自定義View實現時鐘功能_Android
- 2022-09-13 go語言中切片Slice與數組Array對比以及panic:?runtime?error:?inde
- 2022-05-19 C++inline函數的特性你了解嗎_C 語言
- 2023-04-03 Python調試神器之PySnooper的使用教程分享_python
- 2022-09-08 Python中ImportError錯誤的詳細解決方法_python
- 2022-05-27 C++?超詳細分析數據結構中的時間復雜度_C 語言
- 2022-05-05 Entity?Framework使用Fluent?API配置案例_實用技巧
- 最近更新
-
- 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同步修改后的遠程分支