如何在小饰品Python中制作密码和用户名?

发布于 2025-01-29 14:21:22 字数 352 浏览 1 评论 0原文

我尝试了

def main(): 而真: 用户名=输入(“输入用户名:”) 密码=输入(“输入密码:”)

    if UserName == Bob and PassWord == rainbow123:
        time.sleep(1)
        print ("Login successful!")
        logged()

    else:
    print ("Password did not match!")

def loggged(): 时间。 打印(“欢迎到----”)

main(),

不起作用

但我不知道为什么它

i have tried

def main():
while True:
UserName = input ("Enter Username: ")
PassWord = input ("Enter Password: ")

    if UserName == Bob and PassWord == rainbow123:
        time.sleep(1)
        print ("Login successful!")
        logged()

    else:
    print ("Password did not match!")

def logged():
time.sleep(1)
print ("Welcome to ----")

main()

but i dont know why it wont work

somebody plz help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

演多会厌 2025-02-05 14:21:22

问题是您尚未将用户名和密码定义为“ if”语句中的字符串。

import time

def main(): 
    while True: 
        UserName = input("Enter Username: ") 
        PassWord = input("Enter Password: ")

        if UserName == "Bob" and PassWord == "rainbow123":
            time.sleep(1)
            print("Login successful!")
            logged()

        else:
            print("Password did not match!")
def logged(): 
    time.sleep(1) 
    print("Welcome to ----")
main()

The issue is that you haven't defined the username and password as a string in the 'if' statement.

import time

def main(): 
    while True: 
        UserName = input("Enter Username: ") 
        PassWord = input("Enter Password: ")

        if UserName == "Bob" and PassWord == "rainbow123":
            time.sleep(1)
            print("Login successful!")
            logged()

        else:
            print("Password did not match!")
def logged(): 
    time.sleep(1) 
    print("Welcome to ----")
main()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文