亲宝软件园·资讯

展开

Python彩色控制台版

lanxiaofang​​​​​​​ 人气:0

名片管理系统

一、思路

二、用到的知识点

三、效果

四、代码

"""
* @software: PyCharm
* @Description: 名片管理系统
"""
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('=======欢迎进入名片管理系统=======')
print('1.查看名片')
print('2.添加名片')
print('3.修改名片')
print('4.删除名片')
print('5.退出系统')
print(BColors.ENDC)

l = [] # 使用列表,进行数据的增删改查
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('退出成功,欢迎使用本简易名片系统')
break
else:
print('输出错误,请重新输入')
print(BColors.ENDC)

猜拳小游戏

一、思路

二、用到的知识点

三、效果

四、代码

"""

* @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('已退出游戏,游戏结果如下:')
print(BColors.UNDERLINE + '赢:%s 平:%s 输:%s' % (win, ping, lose) + BColors.ENDC)
print('获胜率:', str(win * 100 / (win + ping + lose)) + '%')
break
else:
print(BColors.WARNING + '输入错误' + BColors.ENDC)

加载全部内容

相关教程
猜你喜欢
用户评论