Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- musics={}
- users=[]
- score=0
- def login():
- cusername="a"
- cpassword="123"
- input("PRESS ENTER TO START ")
- username=input("USERNAME: ")
- password=input("PASSWORD: ")
- while password!=cpassword or username!=cusername:
- if username!=cusername:
- print("INVALID USERNAME ")
- if password!=cpassword:
- print("INVALID PASSWORD")
- createusername=input("WOULD YOU LIKE TO CREATE A NEW ACCOUNT??? ")
- if createusername== "yes" or createusername== "Yes" or createusername== "YES":
- cusername=input("WHAT WOULD YOU LIKE YOUR NEW USERNAME TO BE??? ")
- cpassword=input("WHAT WOULD YOU LIKE YOUR NEW PASSWORD TO BE??? ")
- elif createusername!= "yes" or createusername!= "Yes" or createusername!= "YES":
- print("Redirecting...")
- username=input("USERNAME: ")
- password=input("PASSWORD: ")
- print("WELCOME",username)
- def load():
- musicfile=open("musicfile.txt","r")
- #print(musics)
- for line in musicfile:
- parts=line.split(",")
- #creates a dictionary entry for each student – last element in list needs the escape character removing
- musics[str(parts[0])]=parts[1],parts[2].strip("\n")
- musicfile.close()
- #print(musics)
- def loaduser1():
- userfile=open("userfile.txt","r")
- #print(users)
- for line in userfile:
- parts=line.split(",")
- #creates a dictionary entry for each student – last element in list needs the escape character removing
- users.append((parts[0],int(parts[1])))
- userfile.close()
- List=users
- sortedlist=sorted(List,key=lambda x:x[1], reverse= True)
- #print(" L E A D E R B O A R D ")
- for k in range (5):
- position=k+1 #+1 because it starts on 0
- player=sortedlist[k][0]
- score=sortedlist[k][1]
- # print(" "+str(position)+". "+player+" = "+str(score))
- def loaduser():
- userfile=open("userfile.txt","r")
- #print(users)
- for line in userfile:
- parts=line.split(",")
- #creates a dictionary entry for each student – last element in list needs the escape character removing
- users.append((parts[0],int(parts[1])))
- userfile.close()
- List=users
- sortedlist=sorted(List,key=lambda x:x[1], reverse= True)
- print(" L E A D E R B O A R D ")
- for k in range (5):
- position=k+1 #+1 because it starts on 0
- player=sortedlist[k][0]
- score=sortedlist[k][1]
- print(" "+str(position)+". "+player+" = "+str(score))
- def start():
- input("WELCOME TO THE GAME PRESS ENTER TO START")
- input("YOU HAVE TO GUESS WHAT SONG IT IS BY ONLY SEEING THE FIRST LETTER ")
- input("THERE ARE 5 SONGS OF WHICH YOU GET 2 CHANCES TO GUESS RIGHT ")
- input("YOU WILL GET A SCORE OUT OF 10 DEPENDING ON HOW MANY GUESSES IT TAKES FOR YOU TO ANSWER CORRECTLY")
- def play():
- score=0
- print("FINISH THE SONG TITLE")
- for Qu in musics:
- sort=(Qu+" "+musics[Qu][0]+" "+musics[Qu][1])
- #print(sort)#prints artist and song just for testing purposes
- track=musics[Qu][0] #writes the song as the track
- trackwords=track.split(" ") #splits the track into their separate words
- question="" #createsa a blank question
- for word in trackwords:
- question=question+(word[0])+"___ " #adds the first letter of each word each time the loop runs until it runs out of words
- artist=musics[Qu][1] #writes the artist as the artist
- ans1=input(question+" by "+artist+": ") #prints the song with only the first letter of each word and prints the artist out
- if ans1==track:
- #this statement checks whether they got the song right
- print("SMASHED IT YOU GOT IT RIGHT ")
- print ("Score=",score,"+3pts")
- score=score+3
- print("Your Score is now ",score)
- else:
- print("UNLUCKY YOU GOT IT WRONG!!! TRY AGAIN")
- ans1=input(question+" by "+artist+": ") #prints the song with only the first letter of each word and prints the artist out
- if ans1==track:
- print("SMASHED IT YOU GOT IT RIGHT ")
- print ("Score=",score,"+1pts")
- score=score+1
- print("Your Score is now ",score)
- else:
- print("UNLUCKY YOU GOT IT WRONG!!! AGAIN")
- print("The song is "+track)
- print ("Score=",score,"+0pts")
- score=score+0
- print("Your Score is still ",score)
- print("THANK YOU FOR PLAYING ")
- playername=input("ENTER NAME TO BE SAVED TO LEADERBOARD ")
- users.append((playername,score))
- def save():
- userfile=open("userfile.txt","w")
- for user in users:
- userfile.write(user[0]+","+ str(user[1])+"\n")
- userfile.close()
- login()
- load()
- loaduser1()
- start()
- play()
- #save()
- loaduser()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement