Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 在执行定义的语句后,";无”;印刷两次_Python_Function - Fatal编程技术网

Python 在执行定义的语句后,";无”;印刷两次

Python 在执行定义的语句后,";无”;印刷两次,python,function,Python,Function,当我运行下面的代码并完成整个request功能,然后回答n到reqSecPass部分时,它会打印bye,后面是两行,表示None。我如何消除这种情况 您可以看到,再见语句是独立的,我不确定这是否有区别 def goodbye(): print('Good Bye!') def request(): reqPass = input('Which password would you like?[Google, Twitter, Reddit, Computer]') #s

当我运行下面的代码并完成整个
request
功能,然后回答
n
reqSecPass
部分时,它会打印
bye
,后面是两行,表示
None
。我如何消除这种情况

您可以看到,
再见
语句是独立的,我不确定这是否有区别

def goodbye():
    print('Good Bye!')

def request():
    reqPass = input('Which password would you like?[Google, Twitter, Reddit, Computer]')
    #still need to figure out dictionary manipulation so this is a temporary sytem.
    if(reqPass == 'google' or reqPass == 'google'):
        print('________________')
        print('Pass: GOOGLEPASSWORDHERE')
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            print(another())
        else:
            print(goodbye())
    elif(reqPass == 'twitter' or reqPass == 'Twitter'):
        print('_________________')
        print('User: TWITTERUSERNAMEHERE')
        print('Pass: TWITTERPASSWORDHERE')
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            print(another())
        else:
            print(goodbye())
    elif(reqPass == 'computer' or reqPass == 'Computer'):
        print('________________')
        print('Pass: COMPUTERPASSWORDHERE')
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            print(another())
        else:
            print(goodbye())
    elif(reqPass == 'reddit' or reqPass == 'Reddit'):
        print('_________________________')
        print('User: REDDITUSERNAMEHERE')
        print('Pass: REDDITPASSWORDHERE')       
        print('________________')
        reqSecPass = input('Request another password?[y/n]')
        if(reqSecPass == 'y' or reqSecPass == 'Y'):
            print(request())
        else:
            print(goodbye())
print('_____This is a password keeper_____')
#checking if the user has an account
actCheck = input('Do you already have an account?')
if(actCheck == 'Yes' or actCheck == 'yes'):
    #asking for user's name and password
    yourUser = input('___What is your Username?___')
    yourPass = input('___What is your Password?___')
    if(yourUser == 'ari' and yourPass == 'rycbar1234'):
        dirCheck = input('Account settings?[y,n]')
        if(dirCheck == 'y' or dirCheck == 'Y'):
            print('this function is not working yet!')
            actSetCheck = input('Change username or password?')
            if(actSetCheck == 'user' or actSetCheck == 'User' or actSetCheck == 'Username' or actSetCheck == 'username'):
                yourUser = input('What would you like your new username to be?')
            elif(actSetCheck == 'pass' or actSetCheck == 'Pass' or actSetCheck == 'password' or actSetCheck == 'Password'):
                yourPass = input('What would you like your new username to be?')
        elif(dirCheck == 'n' or dirCheck == 'N'):
            print(request())
    else:
        print('Incorrect Username or password')

您正在打印函数的返回值。所有函数都返回
None
(当您不使用显式
return
语句时的默认返回值)

从函数调用中删除
print()
语句,而不是:

print(another())
# ...
print(goodbye())
# ...
print(request())
只用

another()
# ...
goodbye()
# ...
request()
或者,让函数返回要打印的字符串:

def goodbye():
    return 'Good Bye!'

print(goodbye())

虽然可能不值得只使用函数返回单个字符串值。

您正在打印函数的返回值。所有函数都返回
None
(当您不使用显式
return
语句时的默认返回值)

从函数调用中删除
print()
语句,而不是:

print(another())
# ...
print(goodbye())
# ...
print(request())
只用

another()
# ...
goodbye()
# ...
request()
或者,让函数返回要打印的字符串:

def goodbye():
    return 'Good Bye!'

print(goodbye())

虽然可能不值得只使用函数来返回单个字符串值。

您正在打印没有显式
return
语句的函数返回的值。默认情况下,此函数返回的值为
None
。您正在打印此值


有时尝试使用
return
语句,而不是总是打印,例如
return“再见!”

您正在打印没有显式
return
语句的函数返回的值。默认情况下,此函数返回的值为
None
。您正在打印此值


有时尝试使用
return
语句,而不是总是打印,例如
return“再见!”

似乎不返回任何内容的函数返回
,例如
再见
。也就是说,
debye()==None
。函数的默认返回值是
None
您正在函数中打印,然后在调用前后使用
print
调用函数。似乎不返回任何内容的函数返回
None
,例如
debye
。也就是说,
bye()==None
。函数的默认返回值是
None
您正在函数中打印,然后在调用前后使用
print
调用函数。谢谢!我做了您建议的编辑,但是,它仍然在打印“无”,但现在只打印了一次。@AriMadian:所以您有另一个
print()
在某处打印返回值。我没有详细浏览你所有的代码。谢谢!我做了您建议的编辑,但是,它仍然在打印“无”,但现在只打印了一次。@AriMadian:所以您有另一个
print()
在某处打印返回值。我没有详细浏览你所有的代码。