Функция не вызывается внутри другой функции:
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()