未在另一个函数内调用该函数:
ch = False
while not ch:
print("""
1. Make a User
2. Login in and Play
3. Quit
""")
a = input("What would you like to do: ")
if a == '1':
un_maker()
elif a == '2':
player1Login()
elif a == '3':
input('\nEnter to exit...\n')
quit()
当a
为2时,它应该继续前进到player1Login()
,但不会转到player1Login()
内部的下一个函数。
player1Login()
的代码及其应运行的功能:
def player1Login():
""" Login for player 1 """
user1 = input("Please enter your usernames[Caps sensitive]: ") # Asking the
user to input there username
pass1 = input("Please also enter your password[Caps sensitive]: ") # Asking the user to input there password
verfi1(user1, pass1)
def verfi1(user1, pass1):
""" Verfications of the user """
with open("data.csv", "r") as f:
reader = csv.reader(f) # makes 'reader' the csv reader of file 'f'
for row in reader: # Looking at rows/records inside the file
if user1 in row: # Looks for username inside the row
if pass1 in row[1]:
print("Player 1 Confirmed")
player2Login()
elif pass1 != row[1] or reader == '':
print("""You have entered the wrong Username/Password for Player 1
This could be due to:
1. Inputed the wrong username/password
2. Inputed the wrong case in username/password
3. Inputed username/password that does not exit
""")
break
else:
#print("Reader")
next(reader)
基本上,代码应在a
为2,player1Login()
时输出,然后移至verfi1()
函数,但不是,仅返回菜单。
找到答案
def menu():
ch = False
optin = 0
while not ch :
print("""
1. Make a User
2. Login in and Play
3. Quit
""")
optin = input("What would you like to do: ")
if optin == '1':
un_maker()
elif optin == '2':
player1Login()
elif optin == '3':
input('\nEnter to exit...\n')
quit()
def player1Login():
""" Login for player 1 """
user1 = input("Please enter your usernames[Caps sensitive]: ")
pass1 = input("Please also enter your password[Caps sensitive]: ")
boop(user1, pass1)
def boop(user1, pass1):
with open('data.csv', 'r') as f:
reader = csv.reader(f)
for row in reader:
if pass1 in row[1] and user1 in row[0]:
print("Username and Password found, Player 1 Confirmed")
player2Login(user1)
elif pass1 not in row[1] and user1 not in row[0] and row[0] == '' :
print("Player Not found / Password incorrect")
menu()
答案 0 :(得分:1)
您跳过/href=".+\.(?!css|js).+"/
行,因此跳过了next
文件中的其他用户。这可能导致data.csv
永远不会为真,即使if user1 in row
在您的文件中但恰好在跳过的行上。
您的代码:
user1
删除for row in reader: # Looking at rows/records inside the file
if user1 in row: # Looks for username inside the row
if pass1 in row[1]:
print("Player 1 Confirmed")
player2Login()
elif pass1 != row[1] or reader == '':
print("""You have entered the wrong Username/Password for Player 1
This could be due to:
1. Inputed the wrong username/password
2. Inputed the wrong case in username/password
3. Inputed username/password that does not exit
""")
break
else:
next(reader) # this skips the next
条款,因为else
已遍及所有行。