Python3 适合初学者学习的银行账户登录系统实例
一、所用知识点:
1. for循环与if判断的结合
2. %s占位符的使用
3. 辅助标志的使用(标志位)
4. break的使用
二、代码示例:
''' 银行登录系统 ''' uname = "bob" passwd = 123 judgment = 0 choice = 2 for i in range(3): username = input("请输入用户名:") password = int(input("请输入密码:")) if username == uname and password == passwd: #用户名和密码必须同时成立 print("~~~欢迎%s使用银行自助服务系统~~~" %uname) # %s是占位符 judgment = 1 break else: if choice != 0: print("!!!登陆失败!!!" + "您还有" + str(choice) + "次机会") else: print("!!!登陆失败!!!") choice = choice - 1 if judgment == 0: print("三次机会已用完,此卡将冻结10分钟") #只是提示信息,冻结操作并未编写 # 第二种思路 # uname = "bob" # passwd = 123 # # choice = 2 # # for i in range(3): # username = input("请输入用户名:") # password = int(input("请输入密码:")) # if username == uname and password == passwd: # print("~~~欢迎%s使用银行自助服务系统~~~" %uname) # %s是占位符 # # break # else: # if choice != 0: # print("!!!登陆失败!!!" + "您还有" + str(choice) + "次机会") # else: # print("!!!登陆失败!!!") # choice = choice - 1 # else: # print("三次机会已用完,此卡将冻结10分钟") # #
相关推荐
wuxiaosi0 2019-12-16
bcbeer 2019-11-11
Elements小帅 2018-09-14
zhoushanhsan 2008-07-17
wuyufa 2019-07-01
hang0 2017-11-06
MichaelFreeman 2012-02-21
moguibeijing 2019-06-26
庆华 2019-06-26
xiaofeisi 2014-12-30
chaicheng0 2014-12-21
whoandyou 2014-09-17
mongkongstart 2013-07-28
Thanaos 2015-08-28
Lxiaofei 2018-09-23
AI产品经理Pipi 2019-03-11
九三智能控 2017-06-21