注册账号
fp = open("user.txt","a+",encoding="utf-8")
sign = True
accountlist = []
while sign:
name = input("请输入您的用户名")
if '' == name or ' ' in name:
print("抱歉,你的用户名非法")
else:
fp.seek(0)
content = fp.readlines()
for i in content:
res = i.split(":")[0]
accountlist.append(res)
'''
['aa', '111\n']
['bb', '222\n']
['cc', '333\n']
'''
if name in accountlist:
print("抱歉,用户名已经存在")
else:
pwd = input("请输入您的密码:")
if '' == pwd or ' ' in pwd:
print("对不起,密码为空,或者含有空字符,请重新输入")
else:
while True:
pwd2 = input("请确认您的密码:")
if pwd == pwd2:
print("恭喜你~注册成功")
strvar = name+":"+pwd+'\n'
fp.write(strvar)
sign = False
break
else:
print("对不起,两次密码不一致,重新输入")
fp.close()
通讯录
print('|--- 欢迎进入通讯录程序 ---|')
print('|--- 1:查询联系人资料 ---|')
print('|--- 2:插入新的联系人 ---|')
print('|--- 3:删除已有联系人 ---|')
print('|--- 4:退出通讯录程序 ---|')
contacts = dict()
while 1:
instr = int(input('\n请输入相关的指令代码:'))
if instr == 1:
name = input('请输入联系人姓名:')
if name in contacts:
print(name + ' : ' + contacts[name])
else:
print('您输入的姓名不再通讯录中!')
if instr == 2:
name = input('请输入联系人姓名:')
if name in contacts:
print('您输入的姓名在通讯录中已存在 -->> ', end='')
print(name + ' : ' + contacts[name])
if input('是否修改用户资料(YES/NO):') == 'YES':
contacts[name] = input('请输入用户联系电话:')
else:
contacts[name] = input('请输入用户联系电话:')
if instr == 3:
name = input('请输入联系人姓名:')
if name in contacts:
del(contacts[name])
else:
print('您输入的联系人不存在。')
if instr == 4:
break
print('|--- 感谢使用通讯录程序 ---|')
抽奖
import random
print("***********欢迎来到兄弟连抽奖*****************")
print("**************祝您喜提大奖!******************")
list1 = ["青菜","肉","鸡","电脑","笔记本","1个亿"]
while True:
choice = input("\n开始请按enter键!")
res = random.choice(list1)
print("本次抽到的奖品为{}".format(res))
list1.remove(res)
if list1 == []:
print("奖品已经全部抽取完毕!")
break