samedi 10 novembre 2018

I get very strange error while im trying to finish my project

This code is meant to pick an artis from internal file ( text file), read it and pick randomly from the enternal file the artis (that are in the text file in arrey style example: carrot apple bannana), therefore i added .txt to the chosen artist so the program will open artist's file with songs and pick random one of the songs.

import random

loop = False
counter = 0
points = 0
max_level = 10
while loop == False:


   for lines in open("pick.txt").readlines():
          art = lines.split()
          artist = random.choice(art)

   for i in open((artist) + ".txt"):
          song = i.split()
          song_name = random.choice(song)


          print("the song begins with  :" , song_name , "this song is by :" , artist)
          answer = input("Enter full name of the song :  ")

   if answer == song_name:
          points = points +3
          print("correct")
          counter = counter +1
          print(counter)
   elif answer != song_name:
          print("WRONG !!! \n try again")
          dec = input("Please enter the full name of the song :")

          if dec == song_name:
                 points = points +2
                 print("correct")
                 counter = counter +1
                 print(counter)

          elif dec != song_name:
                 print("smh \n WRONG")
                 counter = counter +1
                 print(counter)


   elif counter >= max_level:
          print("The End")
          quit()




   else:
          print("error")


input()

Afterwards when i run the code in python shell , there is a random chance that i get this error , sometimes i get it straight away or later on :

raise IndexError('Cannot choose from an empty sequence') from None IndexError: Cannot choose from an empty sequence




Aucun commentaire:

Enregistrer un commentaire