Python 自学 Day1
作业二:编写登陆接口
- 输入用户名密码
- 认证成功后显示欢迎信息
- 输错三次后锁定
#!/usr/bin/env python
import getpass
def log():
uname = input("input your uname:")
upass = getpass.getpass("input your pass:")
if uname == 'karyn' and upass == 'karyn':
print("welcom login")
exit(0)
else:
print("uname or upass invalid")
count=0
while True:
log()
count +=1
if count>3:
print("error too much")
break
程序练习
请闭眼写出以下程序。
程序:购物车程序
需求:
- 启动程序后,让用户输入工资,然后打印商品列表
- 允许用户根据商品编号购买商品
- 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
- 可随时退出,退出时,打印已购买商品和余额
L=[]
global apple_count,orange_count,bananer_count
apple_count=0;orange_count=0;bananer_count=0
global salary
salary = int(input('inpurt your salary:'))
shop = {'苹果':6,'橘子':5,'香蕉':4,'quit':""}
for i in shop.keys():
L.append(i)
def main():
for j in range(len(L)):
print('{:<8}{:<12}{:<24}'.format(j+1,L[j],shop[L[j]]))
while True:
print('{:<6}{:<8}{:<14}'.format('序号', '名称', '价格(元)'))
main()
choice = input("input your choice :")
if choice == 'q':
print('你买了{}个苹果,{}个橘子,{}个香蕉'.format(apple_count,orange_count,bananer_count))
print("剩余工资:", salary,'元')
exit(1)
elif choice == '1':
if salary >= 6:
apple_count +=1
salary -=6
else:
print("-----你没有钱苹果了-----")
elif choice == '2':
if salary >= 5:
orange_count +=1
salary -=5
else:
print("----你没有钱买橘子了----")
elif choice == '3':
if salary >=4:
bananer_count +=1
salary -=4
else:
print("----你没有钱买香蕉了----")
浙公网安备 33010602011771号