当我运行下面的代码并遍历整个request
函数时,我回答n
到reqSecPass
部分,它会打印goodbye
,后跟两行None
。如何消除此问题?你知道吗
您可以看到goodbye
语句是独立的,我不确定这是否有区别。你知道吗
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()
语句,以便:只是使用
或者,让函数返回要打印的字符串:
尽管仅仅返回单个字符串值可能不值得使用函数。你知道吗
您正在打印没有显式
return
语句的函数返回的值。默认情况下,从这样一个函数返回的值是None
。您正在打印此值。你知道吗有时尝试使用
return
语句而不是总是打印,例如return 'Goodbye!'
。你知道吗相关问题 更多 >
编程相关推荐