作业
# nick = True # while nick: # a_inp = input("请输入用户名:") # if a_inp.isspace() or not a_inp : #:用的isspace()判断是否是空如果是空返回执行 # continue # c_inp = input("请输入密码:") #:用的isspace()判断是否是空如果是空返回执行 # if c_inp.isspace() or not c_inp : # continue # f_inp = input("请输入工作的月份:") # if not f_inp.isdigit(): #:用的not f_inp.isdigit()如果输入的是真的就返回false 就不在执行continue: # continue #: 这是利用了not的原理真返回false假的返回true # h_inp = input("请输入月薪:") # if not h_inp.isdigit(): # continue # print('user:' + a_inp,"\n"'password:' + c_inp,"\n"'work_mons:' + f_inp,"\n"'salary:' + h_inp) # while nick: # good=input('请输入你要执行的操作: \n1,查询总工资\n2,查询用户身份\n3,退出登录)') # if good=='1': #:如果输入的信息为1的话 # f_inp=int(f_inp) #:对月份进行整形 # h_inp=int(h_inp) #:对月工资进行整形 # sum_salary=f_inp*h_inp #:总工资=一共工作了几个月 x 每个月的工资 # print(sum_salary) #:打印出来 # if good=='2': # if a_inp=='alex': # a_id='superuser' # elif a_inp=='wupeiqi' or a_inp=='yanhao': # a_id='normaluser' # else: # a_id='unknowuser' # print(a_id) # elif good=='3': # print("欢迎使用,下次见!") # nick=False
1:编写for循环,利用索引遍历出每一个字符
# msg='hello egon 666' # for i in range(len(msg)): # print(msg[i]) # for i in msg: # print(i)
2:编写while循环,利用索引遍历出每一个字符
# msg='hello egon 666' # i=0 # while i <len(msg): # print(msg[i]) # i=i+1
3:将alex 改成SB
# msg='hello alex' # print(msg.replace("alex","SB"))
4:将该字符串的文件名,文件大小,操作方法切割下来
# msg='/etc/a.txt|365|get' # c = msg.split('|') # print(c)
# 5.编写while循环,要求用户输入命令,如果命令为空,则继续输入
# while True: # i1=input("请输入你的命令:") # if i1=="": # continue; # else: # break;
#:2 # while True: # a=input('请输入命令:') # if a.isspace()or not a : #:如果a是空或者是 # # continue # break;
# 6.编写while循环,让用户输入用户名和密码,如果用户为空或者数字,则重新输入
# while True: # i1=input("请你输入命令:") # try: # il=int(i1) # continue; # except: # if i1=="": # continue; # else: # i2=input("请输入密码:") # break; 2 # while True: # i1=input("请输入用户名:") # if i1.isspace() or i1.isdigit()or not i1 : # continue; # else: # i2=input("请输入密码:") # break;
# 7,.编写while循环,让用户输入内容,判断输入的内容以alex开头的,则将该字符串加上_SB结尾
# h=True; # while h: # h=input('请你输入用户名:') # if h=='alex': # print(h+'_sb') # continue; # else: # print("你好%s"%(h)) # # break;
8
# 1.两层while循环,外层的while循环,让用户输入用户名、密码、工作了几个月、每月的工资(整数),用户名或密码为空,或者工作的月数不为整数,或者
# 月工资不为整数,则重新输入
# 2.认证成功,进入下一层while循环,打印命令提示,有查询总工资,查询用户身份(如果用户名为alex则打印super user,如果用户名为yuanhao或者wupeiqi
# 则打印normal user,其余情况均打印unkown user),退出功能
# 3.要求用户输入退出,则退出所有循环(使用tag的方式)
1 # nick = True 2 # while nick: 3 # a_inp = input("请输入用户名:") 4 # if a_inp.isspace() or not a_inp : #:用的isspace()判断是否是空如果是空返回执行 5 # continue 6 # c_inp = input("请输入密码:") #:用的isspace()判断是否是空如果是空返回执行 7 # if c_inp.isspace() or not c_inp : 8 # continue 9 # f_inp = input("请输入工作的月份:") 10 # if not f_inp.isdigit(): #:用的not f_inp.isdigit()如果输入的是真的就返回false 就不在执行continue: 11 # continue #: 这是利用了not的原理真返回false假的返回true 12 # h_inp = input("请输入月薪:") 13 # if not h_inp.isdigit(): 14 # continue 15 # print('user:' + a_inp,"\n"'password:' + c_inp,"\n"'work_mons:' + f_inp,"\n"'salary:' + h_inp) 16 # while nick: 17 # good=input('请输入你要执行的操作: \n1,查询总工资\n2,查询用户身份\n3,退出登录)') 18 # if good=='1': #:如果输入的信息为1的话 19 # f_inp=int(f_inp) #:对月份进行整形 20 # h_inp=int(h_inp) #:对月工资进行整形 21 # sum_salary=f_inp*h_inp #:总工资=一共工作了几个月 x 每个月的工资 22 # print(sum_salary) #:打印出来 23 # if good=='2': 24 # if a_inp=='alex': 25 # a_id='superuser' 26 # elif a_inp=='wupeiqi' or a_inp=='yanhao': 27 # a_id='normaluser' 28 # else: 29 # a_id='unknowuser' 30 # print(a_id) 31 # elif good=='3': 32 # print("欢迎使用,下次见!") 33 # nick=False