Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
splitting a random song
#1
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()
Reply


Messages In This Thread
splitting a random song - by Unknown_Relic - Nov-14-2019, 10:37 AM
RE: splitting a random song - by ichabod801 - Nov-14-2019, 01:28 PM
RE: splitting a random song - by baquerik - Nov-15-2019, 01:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Song Modifying Program Starting Point BadenJaden 1 1,906 Mar-27-2020, 11:36 AM
Last Post: pyzyx3qwerty
  random selection of song and artist not working Unknown_Relic 2 2,375 Nov-08-2019, 02:06 PM
Last Post: perfringo
  How to play a song .wav or .mp3 with audioop native library IvanSilva 3 6,597 Mar-14-2018, 10:49 AM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020