samedi 20 novembre 2021

how to get a random line in a csv file and to output the first 2 columns of that randomly chosen line ? (gcse python)

I'm currently doing a music quiz where I need to find a random line out of my CSV file(which was written in excel) and output the first and second columns of that line but every time I run it it says some kind of attribute error. Here is my code so far : for line in file : lines = line.split(",") myline = random.choice(lines.randrange(1,50)) unknown = myline(lines[0]) artist = myline(lines[2]) song = myline(lines[1]) while attempts >= 1 : //Maximum 2 chances to get the correct answer. print("The RANDOM SONG chosen for you is :"+unknown+ " by" +artist+ "")

I am a complete beginner with regards to this kind of stuff so any corrections would be very welcome :)




Aucun commentaire:

Enregistrer un commentaire