标签:切割 去除空格 pass ase replace src for 分享 索引
1 msg = ‘hello egon 666‘ 2 for i in msg[0:len(msg)]: 3 print(i)
1 msg = ‘hello egon 666‘ 2 count =0 3 while count < len(msg): 4 print(msg[count]) 5 count += 1
1 msg = ‘hello alex‘ 2 print(msg.replace(‘alex‘,‘SB‘)) #str.replace()
1 msg = ‘/etc/a.txt|365|get‘ 2 print(msg.split(‘|‘,)) #str.split()
1 while True: 2 ret = input(‘please input cmd>>>‘) 3 if ret == ‘‘: 4 continue 5 ret = ret.strip() #去除空格 6 print(‘执行该命令:%s‘ %ret) 7 break
1 while True: 2 user = input(‘请输入用户名:‘) 3 passwd = input(‘请输入密码:‘) 4 user = user.strip() 5 if user.isdigit() or user == ‘‘: 6 continue 7 else: 8 print(‘恭喜登陆成功!‘) 9 break
1 while True: 2 ret = input(‘请输入内容:‘) 3 if ret.startswith(‘alex‘): 4 ret += ‘_SB‘ 5 print(ret)
两层while循环,外层的while循环,让用户输入用户名、密码、工作了几个月、
每月的工资(整数),用户名或密码为空,或者工作的月数不为整数,或者
月工资不为整数,则重新输入
1 tag = True 2 while tag: 3 user = input(‘请输入用户名:‘) 4 passwd = input(‘请输入密码:‘) 5 user = user.strip() 6 passwd = passwd.strip() 7 if user == ‘‘ or passwd == ‘‘: 8 print(‘用户或密码输入错误,请从新输入‘) 9 continue 10 else: 11 print(‘登陆成功!‘) 12 while tag: 13 mounth = (input(‘工作了几个月:‘)) 14 mounth_mouey = (input(‘每月工资(整数):‘)) 15 if mounth.isdigit() and mounth_mouey.isdigit(): 16 while tag: 17 print(‘命令提示\n1.查询总工资\n2.查询用户身份\n3.退出‘) 18 user_choose = (input(">>>")) 19 if user_choose == ‘1‘: 20 total_money = int(mounth) * int(mounth_mouey) 21 print(total_money,‘元‘) 22 elif user_choose == ‘2‘: 23 if user == ‘alex‘: 24 print(‘super user‘) 25 elif user == ‘yuanhao‘ or user == ‘wupeiqi‘: 26 print(‘normal user‘) 27 else: 28 print(‘unkown user‘) 29 elif user_choose == ‘3‘: 30 tag = False 31 else: 32 print(‘月份与工资请输入整数‘) 33 continue
View Code
标签:切割 去除空格 pass ase replace src for 分享 索引
原文地址:http://www.cnblogs.com/zzn91/p/6985082.html