Coding Global Background
Coding Global

anyone know why my code says authentication was accepted but it doesnt break out of the loop?

Archiviert 2 years ago
1 Nachrichten
0 Mitglieder
2 years ago
In Discord öffnen
X
xaavair

my code for reference: ```py import json import random import time def load_accounts(): with open("accounts.json", "r") as json_file: data = json.load(json_file) # Opens json file as data return data["users"] def authenticate(): users = load_accounts() if not users: print("Error loading accounts.") return False username_input = input("Username: ") # Gets username input for user in users: #Iterates through each of the values in the 'users' list if username_input == user.get("name"): # Checks if inputted username is in that iteration password_input = input("Password: ") # If it is it asks for the password if password_input == user.get("password"): # Checks if the password matches the one in the json file print("Authentication successful.") return True else: print("Invalid password. Retry.") # Wrong password prints this return False else: print("Invalid username. Retry.") # Wrong username prints this return False def select_song(): with open('songs.json') as songs_file: songs = json.load(songs_file) random_song = random.choice(songs) return random_song def play_game(): if authenticate(): time.sleep(1) print("Let's play the game.") else: print("Authentication failed.") def main(): play_game() authenticate() # Runs function main() # Runs function ```

Antworten (1)