Nov-14-2019, 10:37 AM
this is meant to be a music quiz where they login and need to guess the song by the first letters of each word in the title. When im run the code i get an error with the split_song. Im fairly new to python and i cant find how to fix it.
import random def access_data(): with open("Passwords.txt", "r") as f: passwords = [line.rstrip("\n") for line in f] with open("Usernames.txt", "r") as f: usernames = [line.rstrip("\n") for line in f] with open("Songnames.txt", "r") as f: songnames = [line.strip("\n") for line in f] with open("songartists.txt", "r") as f: songartists = [line.strip("\n") for line in f] return passwords, usernames, songnames, songartists def login(usernames, passwords): enter_username = input("Input your username") if enter_username in usernames: enter_password = input("Input your password") if enter_password in passwords: username_pos = usernames.index(enter_username) password_pos = passwords.index(enter_password) if username_pos == password_pos: print("well done you logged in", enter_username) return True else: print("your password does not match the username") else: print("password not found") else: print("username is not authorised") return False def song_selection(songnames, songartists): random_song = random.choice(songnames) random_songPos = songnames.index(random_song) random_artist = songartists[random_songPos] print(random_song, "/", random_songPos, "/", random_artist) return random_song, random_artist def split_song(songnames): print(songnames) for letter in songnames.split(" "): print(letter[0]) def main(): passwords, usernames, songnames, songartists = access_data() success = login(usernames, passwords) if success == True: while True: random_song, random_artist = song_selection(songnames, songartists) split_song(songnames) break main()