【发布时间】:2019-09-18 23:36:59
【问题描述】:
我有一个关于 Python 的简单问题。编写一个程序,要求用户输入密码。
如果用户输入了正确的密码,程序应该告诉他们他们已经登录到系统。
否则,程序应该要求他们重新输入密码。用户应该只能尝试五次输入密码,然后程序应该告诉他们他们被踢出系统。
我已经解决了这个问题,但我不知道我的函数中是否需要参数。另一个问题是我应该在程序中返回什么。我把 return 0 但我不希望 0 出现在调试器中。
def code():
global password
password='123456'
global total_guesses
total_guesses=5
while total_guesses<=5 and total_guesses>0:
resposta=input('Digite password\n')
if password==resposta:
print('You have entered the system')
break
else:
print('Wrong password you haver',total_guesses,'total_guesses')
total_guesses-=1
return 0
print(code())
【问题讨论】:
-
您可以肯定地对密码和total_guesses进行参数化,并根据某些条件决定是否返回值! @Luismaia1994
标签: python-3.x return arguments