【问题标题】:repeat a function while loop not end in python在python中循环未结束时重复一个函数
【发布时间】:2020-03-20 23:52:54
【问题描述】:

嘿,伙计们,我正在玩我的小项目,我遇到了如何重复功能的问题 我试图在while循环中调用它自己的函数,但没有工作可能使用另一个函数来这样做,比如调用另一个函数再次调用这个函数

代码如下:

 #this function is to check user and pass that was entered by the user using the inputs function

 def chk(u = str(a[0]), p = int(a[1])):
    while u not in sales_man.keys():
    call this function again

【问题讨论】:

  • 您为什么要为您的参数指定来自未知对象a 的默认值?您的意思是def chk(u, p): ... 后跟chk(str(a[0]), int(a[1]) 之类的调用,还是要将a 作为def chk(x): u = str(x[0]); p = int(x[1]); ... 的参数,然后调用chk(a)

标签: python function repeat


【解决方案1】:

如果您尝试实现简单的登录,您可以使用经典的无限循环,例如:

def check_user(user):
    return user in sales_man.keys()


while True:
    # [...] get username in input

    if check_user(username):
        # [...] ok, check password
    else:
        # [...] wrong user

【讨论】:

    猜你喜欢
    • 2015-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-11-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多