Python名片管理系統(tǒng)+猜拳小游戲案例實(shí)現(xiàn)彩(色控制臺(tái)版)
名片管理系統(tǒng)
一、思路
- 1、定義名片操作選項(xiàng)
- 2、把增加的名片信息存儲(chǔ)到字典中
- 3、所有名片信息存儲(chǔ)到列表
- 4、對(duì)于誤操作給出提示
二、用到的知識(shí)點(diǎn)
- 1、類的定義,用來設(shè)置控制臺(tái)輸出顏色
- 2、函數(shù)的定義,用來輸出歡迎與選項(xiàng)
- 3、if elif else 對(duì)選擇的選項(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('請(qǐng)選擇: ') # 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('請(qǐng)選擇要修改的名片的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('請(qǐng)選擇要?jiǎng)h除的名片: ')
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ò)誤,請(qǐng)重新輸入')
print(BColors.ENDC)猜拳小游戲
一、思路
- 1、控制臺(tái)輸入數(shù)字代表石頭剪刀布,用隨機(jī)數(shù)隨機(jī)石頭剪刀布
- 2、對(duì)比控制臺(tái)輸入和隨機(jī)到的結(jié)果
- 3、設(shè)置輸出顏色
- 4、記錄勝利、平局、失敗次數(shù)
- 5、輸入不在設(shè)定范圍內(nèi)提示輸入有誤
- 6、退出游戲告知?jiǎng)俾?/li>
二、用到的知識(shí)點(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 + '請(qǐng)出: ' + 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)彩色控制臺(tái)版的文章就介紹到這了,更多相關(guān)Python彩色控制臺(tái)版內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(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)(控制臺(tái)版)
- 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)文章
YOLOv5構(gòu)建安全帽檢測和識(shí)別系統(tǒng)使用詳解
這篇文章主要為大家介紹了YOLOv5構(gòu)建安全帽檢測和識(shí)別系統(tǒng)使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-04-04
python雙向鏈表實(shí)現(xiàn)實(shí)例代碼
python雙向鏈表和單鏈表類似,只不過是增加了一個(gè)指向前面一個(gè)元素的指針,下面的代碼實(shí)例了python雙向鏈表的方法2013-11-11
數(shù)據(jù)清洗之如何用一行Python代碼去掉文本中的各種符號(hào)
我們?cè)谔幚砦谋镜臅r(shí)候往往需要對(duì)標(biāo)點(diǎn)符號(hào)進(jìn)行處理,下面這篇文章主要給大家介紹了關(guān)于數(shù)據(jù)清洗之如何用一行Python代碼去掉文本中的各種符號(hào)的相關(guān)資料,文中通過實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-11-11
Python 實(shí)現(xiàn)兩個(gè)列表里元素對(duì)應(yīng)相乘的方法
今天小編就為大家分享一篇Python 實(shí)現(xiàn)兩個(gè)列表里元素對(duì)應(yīng)相乘的方法,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-11-11
Python&Matlab實(shí)現(xiàn)螞蟻群算法求解最短路徑問題的示例
本文主要介紹了Python&Matlab實(shí)現(xiàn)螞蟻群算法求解最短路徑問題的示例,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-03-03
Python 檢查數(shù)組元素是否存在類似PHP isset()方法
isset方法來檢查數(shù)組元素是否存在,在Python中無對(duì)應(yīng)函數(shù),在Python中一般可以通過異常來處理數(shù)組元素不存在的情況,而無須事先檢查2014-10-10
OpenCV+python實(shí)現(xiàn)實(shí)時(shí)目標(biāo)檢測功能
這篇文章主要介紹了OpenCV+python實(shí)現(xiàn)實(shí)時(shí)目標(biāo)檢測功能,本文通過實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06

