【发布时间】:2019-02-27 14:12:41
【问题描述】:
我已经构建了一个代码来执行一个简单的任务,即输入用户名和密码,检查它们是否满足条件,如果它们不正确则重复该过程,或者如果正确则停止程序。但是,while 循环不会停止,程序会继续运行。我在下面插入了代码。当条件满足时如何让while循环停止?
def loginConfirmation(user1,user2,pass1,pass2,confirm1,confirm2):
if len(user1) > 6:
confirm1 = confirm1 + 1
else:
print("Invalid username Player 1")
if len(user2) > 6:
confirm2 = confirm2 + 1
else:
print("Invalid username Player 2")
if pass1 == ("password"):
confirm1 = confirm1 + 1
else:
print("invalid passsword Player 1")
if pass2 == ("password"):
confirm2 = confirm2 + 1
else:
print("Invalid passsword Player 2")
confirmation = confirm1 + confirm2
return confirmation
confirmation = 0
confirm1 = 0
confirm2 = 0
while confirmation != 4:
print("Please enter your details below. Usernames must be at least six letters long.")
user1 = input("Player 1, enter your username: ")
pass1 = input("Player 1, enter your password: ")
user2 = input("Player 2, enter your username: ")
pass2 = input("Player 2, enter your password: ")
loginConfirmation (user1,user2,pass1,pass2,confirm1,confirm2)
【问题讨论】:
-
您永远不会将
loginConfirmation的输出分配给确认。试试confirmation=loginConfirmation (user1,user2,pass1,pass2,confirm1,confirm2) -
(问题在被回答时不会在此处关闭。仅当它们被视为离题或无法回答时才关闭)。
-
我知道这个话题不是封闭的。我只是明确表示问题已解决
标签: python python-3.x while-loop