Nov-08-2019, 11:38 AM
im trying to select a random song in a file then find the position and match it with the artist in a separate file in python 3.7.3. Two files called songnames, songartists. Im want to print the song and artist but i keep getting a value error. Im new to python and not sure 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 song_selection(songnames, songartists): random_song = random.choice(songnames) random_songPos = songnames.index(random_song) random_artist = songartists[random_songPos] print(random_song, random_artist) return random_song, random_artist songnames, songartists, songnames, songartists = access_data() song_selection(songnames, songartists)