标签:hone 列表 退出 wan tabs 一键 upper 员工 等于
# 随机产生10个10以内的整型数,存放到列表中,将列表中的最大值放在列表的最后 import random
li = [] tmp = random.randint(1, 10) print(tmp) li.append(tmp) i = 1 while i < 10: tem = random.randint(1, 10) print(tem) if tem > li[i - 1]: li.append(tem) else: li.insert(i - 1, tem) i += 1 print(li)
# 随机产生10个10以内的整型数,存放到列表中,将列表从小到大排序
import random li = [] lis = [] i = 0 j = 0 while i < 10: tmp = random.randint(1, 10) li.append(tmp) i += 1 # 随机生成10个10以内的整型数 while j < 10: tem = min(li) # 求出列表最小值 v = li.index(tem) # 求出列表最小值索引 s = li.pop(v) # 删除列表最小值,并返回最小值 lis.append(s) # 最小值添加到新列表中,从左到右 j += 1 print(lis)
# 我们将三位整型数的每一位的立方和等于数值本身的数称为水仙花数,有多少个水仙花数(一定是三位数) i = 100 count = 0 while i < 1000: 水仙花 = (i // 100) ** 3 + (i % 100 // 10) ** 3 + (i % 10) ** 3 if i == 水仙花: print(‘水仙花=‘, 水仙花) count = count + 1 else: pass i = i + 1 print(count)
‘‘‘ 后台管理员只有一个用户: admin, 密码: admin 当管理员登陆成功后, 可以管理前台会员信息. 会员信息管理包含: 1.添加会员信息 2.删除会员信息 3.查看会员信息 4.退出 ‘‘‘ ‘‘‘ i=0 while i<3: name = input(‘请输入登录账号:‘) passwd = input(‘请输入密码:‘) s = login(name, passwd) if s==‘恭喜登录成功‘: break else: print(s) i=i+1 if s!=‘恭喜登录成功‘: print(‘账户已被锁定‘) else: print(s) ‘‘‘ #登录 def login(name,passwd): if name != ‘admin‘: return ‘账户不正确‘ else: if passwd != ‘admin‘: return ‘密码错误‘ else: return ‘恭喜登录成功‘ def memadd(): mema=‘会员名\t手机号\t性别\t年龄\t邮箱\n‘ while True: mem = input(‘请输入会员名称:‘) if mem ==‘q‘ or mem ==‘Q‘: return mema else: mem = mem[0:10] phone = input(‘请输入手机号:‘) if phone ==‘q‘ or phone ==‘Q‘: return mema else: phone = phone[0:11] sex = input(‘请输入性别:‘) if sex==‘q‘ or sex ==‘Q‘: return mema else: sex = sex[0:1] age = input(‘请输入年龄:‘) if age==‘q‘ or age ==‘Q‘: return mema else: age = age[0:3] emil = input(‘请输入邮箱‘) if emil==‘q‘ or emil ==‘Q‘: return mema else: emil = emil[0:20] temp = ‘{}\t{}\t{}\t{}\t{}\n‘ s = temp.format(mem, phone, sex, age, emil) mema = mema + s return mema table=‘‘ op=input(‘请输入操作类型:‘) if op==‘添加‘: ta=memadd() table=table+ta else: pass print(table.expandtabs(20)) #查看 oth=input(‘是否还需要其他操作:y or n:‘) if oth==‘n‘: print(‘end‘) else: pass
staff_table = [ [1, ‘Alex Li‘, 22, ‘13651054608‘, ‘IT‘, ‘2013-04-01‘], [2, ‘Jack Wang‘, 30, ‘13304320533‘, ‘it‘, ‘2013-05-03‘], [3, ‘Rain Liu‘, 25, ‘13354320533‘, ‘Sales‘, ‘2016-04-22‘], [4, ‘Mack Cao‘, 40, ‘13567320533‘, ‘HR‘, ‘2009-03-01‘], [5, ‘lijinping‘, 40, ‘135673205335‘, ‘HR‘, ‘2009-03-01‘] ] name = [] age = [] phone = [] dept = [] enroll_date = [] s_id =[] for i in staff_table: s_id.append(i[0]) for i in staff_table: name.append(i[1]) for i in staff_table: age.append(i[2]) for i in staff_table: phone.append(i[3]) for i in staff_table: dept.append(i[4]) for i in staff_table: enroll_date.append(i[5]) def operation(): op=input(‘请输入操作类型: 1.创建员工记录 2:删除员工信息 3:修改员工信息 4:查询员工信息 其他数字:退出系统:‘) if int(op)==1: add_staffinfo() elif int(op)==2: del_staffinfo() elif int(op)==3: mod_staffinfo() elif int(op) == 4: query_staffinfo() else: print(‘\033[45;1m已退出,欢迎下次光临\033[0m‘) return #查询员工信息 def query_staffinfo(): qu=int(input(‘输入查询条件: 1:all 2:age 4:dept 5:enroll_date:‘)) if qu==4: de=input(‘输入具体要查询的职能名称:‘) dept_p=[] for i in staff_table: if i[4].upper()==de.upper(): dept_p.append(i) print(dept_p) # 打印dept = "IT"的个人所有信息 print(len(dept_p)) # 打印满足条件的条数 elif qu==5: enr= input(‘输入年份,查询这一年入职的员工:‘) enroll_d = [] for i in staff_table: if i[5].startswith(enr): enroll_d.append(i) print(enroll_d) print(len(enroll_d)) elif qu==2: info = list(zip(name, age)) # 提取info列表中的name和age组成新的列表 age_l=int(input(‘输入要查询的年龄范围:(例如:18)‘)) res_agel=set() for i in info: if i[1]>age_l: res_agel.add(i) print(res_agel) print(len(res_agel)) elif qu==1: print(staff_table) return operation() # 可创建新员工纪录,以phone做唯一键,staff_id需自增 def add_staffinfo(): n_name = input(‘input name:‘) n_age = int(input(‘input age:‘)) n_phone = str(input(‘input phone:‘)) n_dept = input(‘input dept:‘) n_enroll_date = input(‘input enroll_date:‘) n = len(staff_table) + 1 if n_phone in phone: print(‘手机号已存在‘) else: staff_table.append([n, n_name, n_age, n_phone, n_dept, n_enroll_date]) s_id.append(n) name.append(n_name) age.append(n_age) phone.append(n_phone) dept.append(n_dept) enroll_date.append(n_enroll_date) return operation() # 可删除指定员工信息纪录,输入员工id,即可删除 def del_staffinfo(): sid = int(input(‘input staff_id:‘)) def soo(): for i in staff_table: if i[0] == sid: return i if sid not in s_id: print(‘删除的员工信息不存在‘) else: staff_table.remove(soo()) print(‘员工id:%d的信息已被删除‘ % sid) return operation() #可修改员工信息 def mod_staffinfo(): count = int(input(‘请输入要修改的事项 1:name 2:age 3:phone 4:dept 5:enroll_date: ‘)) old_info = str(input(‘输入修改前内容:‘)) new_info = str(input(‘输入修改后内容:‘)) def mod(o, n, c=count): if c == 1 or c == 2 or c == 4 or c == 5: for i in staff_table: if o == str(i[c]): i[c] = new_info elif c == 3: for i in staff_table: if o == i[c]: if n not in phone: i[c] = new_info else: print(‘手机号已存在‘) #phone为主键 else: print(‘修改内容不存在‘) mod(old_info, new_info) print(staff_table) return operation() operation()
标签:hone 列表 退出 wan tabs 一键 upper 员工 等于
原文地址:https://www.cnblogs.com/lijinping716/p/11327180.html