Python名片管理系統(tǒng)+猜拳小游戲案例實(shí)現(xiàn)彩(色控制臺版)
更新時(shí)間:2022年08月14日 16:30:26 作者:lanxiaofang???????
這篇文章主要介紹了Python名片管理系統(tǒng)+猜拳小游戲案例實(shí)現(xiàn)彩(色控制臺版),文章圍繞主題展開詳細(xì)的內(nèi)容介紹,具有一定的參考價(jià)值,感興趣的小伙伴可以參考一下
名片管理系統(tǒng)
一、思路
- 1、定義名片操作選項(xiàng)
- 2、把增加的名片信息存儲到字典中
- 3、所有名片信息存儲到列表
- 4、對于誤操作給出提示
二、用到的知識點(diǎn)
- 1、類的定義,用來設(shè)置控制臺輸出顏色
- 2、函數(shù)的定義,用來輸出歡迎與選項(xiàng)
- 3、if elif else 對選擇的選項(xiàng)做出判斷
三、效果
四、代碼
""" * @software: PyCharm * @Description: 名片管理系統(tǒng) """ class BColors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' def cardHead(): print(BColors.HEADER) print('=======歡迎進(jìn)入名片管理系統(tǒng)=======') print('1.查看名片') print('2.添加名片') print('3.修改名片') print('4.刪除名片') print('5.退出系統(tǒng)') print(BColors.ENDC) l = [] # 使用列表,進(jìn)行數(shù)據(jù)的增刪改查 while True: cardHead() choose = input('請選擇: ') # input 輸出都是字符串 print(BColors.OKBLUE) if choose == '1': i = 0 if len(l) == 0: print('暫無名片') else: while i < len(l): print('%s->姓名:%s | 年齡:%s | 身高:%s' % (i, l[i]['name'], l[i]['age'], l[i]['high'])) i += 1 elif choose == '2': name = input('name: ').strip() age = input('age: ').strip() high = input('high: ').strip() info = {'name': name, 'age': age, 'high': high} l.append(info) print('添加成功') elif choose == '3': revise = input('請選擇要修改的名片的ID: ') if int(revise) >= len(l): print('該ID不存在') else: name1 = input('name: ') age1 = input('age ') high1 = input('high: ') if name1: l[int(revise)]['name'] = name1 if age1: l[int(revise)]['age'] = age1 if high1: l[int(revise)]['high'] = high1 print('修改成功') elif choose == '4': del1 = input('請選擇要刪除的名片: ') if int(del1) >= 0 and int(del1) < len(l): l.remove(l[int(del1)]) print('刪除成功') else: print('該ID不存在') elif choose == '5': print('退出成功,歡迎使用本簡易名片系統(tǒng)') break else: print('輸出錯(cuò)誤,請重新輸入') print(BColors.ENDC)
猜拳小游戲
一、思路
- 1、控制臺輸入數(shù)字代表石頭剪刀布,用隨機(jī)數(shù)隨機(jī)石頭剪刀布
- 2、對比控制臺輸入和隨機(jī)到的結(jié)果
- 3、設(shè)置輸出顏色
- 4、記錄勝利、平局、失敗次數(shù)
- 5、輸入不在設(shè)定范圍內(nèi)提示輸入有誤
- 6、退出游戲告知勝率
二、用到的知識點(diǎn)
- 1、類的定義,用來設(shè)定輸出顏色
- 2、判斷if elif else 的使用
- 3、在死循環(huán)中退出循環(huán) break
- 4、隨機(jī)函數(shù) random
- 5、字符串相等 ==
- 6、and or
三、效果
四、代碼
""" * @software: PyCharm * @Description: 猜拳小游戲 """ import random class BColors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' BOLD = '\033[1m' UNDERLINE = '\033[4m' lose = 0 win = 0 ping = 0 while True: print(BColors.HEADER + '**************************歡迎來猜拳*******************' + BColors.ENDC) print('1 剪刀 2 石頭 3 布 4 退出游戲') print(BColors.UNDERLINE + '贏:%s 平:%s 輸:%s' % (win, ping, lose) + BColors.ENDC) robot = random.choice(['剪刀', '布', '石頭']) h = input(BColors.BOLD + '請出: ' + BColors.ENDC) if (h == '1' and robot == '布') or (h == '2' and robot == '剪刀') or (h == '3' and robot == '石頭'): win += 1 print(BColors.OKGREEN + '很高興,你贏了' + BColors.ENDC) elif (h == '1' and robot == '剪刀') or (h == '2' and robot == '石頭') or (h == '3' and robot == '布'): ping += 1 print(BColors.OKBLUE + '很高興,平局' + BColors.ENDC) elif (h == '1' and robot == '石頭') or (h == '2' and robot == '布') or (h == '3' and robot == '剪刀'): lose += 1 print(BColors.FAIL + '很高興,它贏了' + BColors.ENDC) elif h == '4': print('已退出游戲,游戲結(jié)果如下:') print(BColors.UNDERLINE + '贏:%s 平:%s 輸:%s' % (win, ping, lose) + BColors.ENDC) print('獲勝率:', str(win * 100 / (win + ping + lose)) + '%') break else: print(BColors.WARNING + '輸入錯(cuò)誤' + BColors.ENDC)
到此這篇關(guān)于Python名片管理系統(tǒng)彩色控制臺版的文章就介紹到這了,更多相關(guān)Python彩色控制臺版內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
您可能感興趣的文章:
- python實(shí)現(xiàn)簡單的名片管理系統(tǒng)
- Python實(shí)戰(zhàn)之實(shí)現(xiàn)簡單的名片管理系統(tǒng)
- python實(shí)現(xiàn)簡易名片管理系統(tǒng)
- python3實(shí)現(xiàn)名片管理系統(tǒng)(控制臺版)
- python名片管理系統(tǒng)開發(fā)
- 使用python實(shí)現(xiàn)名片管理系統(tǒng)
- 用python實(shí)現(xiàn)名片管理系統(tǒng)
- Python實(shí)現(xiàn)名片管理系統(tǒng)
- Python綜合應(yīng)用名片管理系統(tǒng)案例詳解
- python實(shí)現(xiàn)一個(gè)函數(shù)版的名片管理系統(tǒng)過程解析
- 如何使用Python實(shí)現(xiàn)名片管理系統(tǒng)
相關(guān)文章
如何在scrapy中集成selenium爬取網(wǎng)頁的方法
這篇文章主要介紹了如何在scrapy中集成selenium爬取網(wǎng)頁的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-11-11python 從csv讀數(shù)據(jù)到mysql的實(shí)例
今天小編就為大家分享一篇python 從csv讀數(shù)據(jù)到mysql的實(shí)例,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-06-06python和shell監(jiān)控linux服務(wù)器的詳細(xì)代碼
這篇文章主要為大家介紹了使用python和shell監(jiān)控linux服務(wù)器的詳細(xì)代碼,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-06-06python+pyqt5實(shí)現(xiàn)24點(diǎn)小游戲
這篇文章主要為大家詳細(xì)介紹了python+pyqt5實(shí)現(xiàn)24點(diǎn)小游戲,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-01-01