Python四

第一题

ls = "123456789"
ls1 = "23456789456123"
result = ls.find(ls1)
if result != -1:
    print("是")
else:
    print("不是")

先写两个字符串ls = "123456789" 、ls1 = "23456789456123" 然后设置成 ls 来找 ls1 ,并且假设 if 里等于 -1 的话就打印 "是" , 不是的话就打印 "不是"  然后就以此来判断字符串是否相等

第二题

ls = "123456789"
ls1 = "23456789456123"
for char in ls:
    if char not in ls1:
        print("不在ls1里")
        break
    else:
        print("在ls1里")
        break

建立两个字符串 ls = "123456789" 和 ls1 = "23456789456123" ,运用for来判断字符是否相同 for char in ls1 来判断,最后用 if 来确定以及判断

第三题

ls = "123456789141252363343abcdefg"
if ls.isdigit() and ls.isalpha():
    print("字符串里只有数字或者字母")
else:
    print("字符串里既有数字或者字母")

用 ls.isdigit() 或者 ls.isalpha()来判断在 ls 字符串里是否有数字和字母

第四题

import sys
menu = """
"""
def show_info(info: str):
    print("#" * 20)
    print(info.center(20, "#"))
    print("#" * 20)

while True:
    print(menu)
    num = input("点击进入登录页面")
    if num == "1":
        account = input("输入用户名")
        password = input("请输入密码")
        confirm = input("请确认密码")
        if password != confirm:
            show_info("密码错误,请再尝试一次")
        else:
            with open("account.txt", "at") as f:
                text = account + ":" + password + "\n"
                f.write(text)
        show_info("注册成功")
    elif num == "2":
        account = input("请输入账户")
        password = input("请输入密码")
        with open("account.txt", "rt") as file:
            text = file.readline()
            local_account = text.split(":")[0]
            local_password = text.split(":")[1].replace("\n", "2")
            if account == local_account and local_password == password:
                show_info("登陆成功")
            else:
                show_info("登陆失败")
    elif num == "3":
        show_info('谢谢使用')
        sys.exit()
    else:
        print()
        show_info("请输入有效数字".center(50, "1"))

  • 7
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值