python之自练小程序(字符串方法)

# 编写者:song
# 编写for循环,利用索引遍历出每一个字符

'''msg='hello egon 666'

for i in msg:
    print(i)'''


# 编写while循环,利用索引遍历出每一个字符

'''msg = 'hello egon 666'
i = 0
while i<len(msg):
    print(msg[i])
    i+=1'''

# msg='hello alex'中的alex替换成SB

'''msg='hello alex'

print(msg.replace('alex','SB'))'''

# 将该字符的文件名,文件大小,操作方法切割出来

'''msg='/etc/a.txt|365|get'

print(msg.split('/'))'''

# 编写while循环,要求用户输入命令,如果命令为空,则继续输入
'''tag = True
while tag:
    cmd = input("请输入: ")
    if len(cmd) != 0:
        tag = False
    else:
        continue'''

#编写while循环,让用户输入用户名和密码,如果用户为空或者数字,则重新输入

'''tag = True
while tag:
    real_name = input("请输入您的用户名:  ")
    real_password = input("请输入您的密码:  ")
    if len(real_name) == 0 or real_name.isdigit():
        continue
    else:
        tag = False'''

# 编写while循环,让用户输入内容,判断输入的内容以alex开头的,则将该字符串加上_SB结尾

'''tag = True
while tag:
    msg = input("请开始您的表演:  ")
    if msg.find("alex",0,4) == 0:
        sen = "_SB"
        print(msg+sen)
    else:
        tag = False'''


# 1.两层while循环,外层的while循环,让用户输入用户名、密码、工作了几个月、每月的工资(整数),
# 用户名或密码为空,或者工作的月数不为整数,或者月工资不为整数,则重新输入
# 2.认证成功,进入下一层while循环,打印命令提示,有查询总工资,查询用户身份(如果用户名为alex则打印super user,
# 如果用户名为yuanhao或者wupeiqi则打印normal user,其余情况均打印unkown user),退出功能
# 3.要求用户输入退出,则退出所有循环(使用tag的方式)

tag = True
while tag:
    name = input("请输入您的用户名:  ")
    password = input("请输入您的密码:  ")
    work_month = input("请输入您工作了几个月:  ")
    salary = input("请输入您每月的工资:  ")
    if len(name) == 0 or len(password) == 0:
        continue
    elif work_month.isdigit() and salary.isdigit():
        print("小子,你认证成功了")
        while tag:
            print("本系统有以下功能")
            print("1.查询总工资")
            print("2.查询用户身份")


            options = int(input("输入 1 查询总工资,输入 2 查询用户身份"))
            if options == 1:
                x = int(work_month)
                y = int(salary)
                print(x*y)
                print("退出本系统请输入 3")
                print("输入任意键返回上一层")
                options1 = int(input("command========>"))
                if options1 == 3:
                    tag =False
            elif options == 2:
                if name == "alex":
                    print("super user")
                elif name == "wupeiqi" or name == "yuanhao":
                    print("normal user")
                else:
                    print("unkown user")
                print("退出本系统请输入 3")
                print("输入任意键返回上一层")
                options2 = int(input("command========>"))
                if options2 == 3:
                    tag =False

            else:
                continue
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值