Advertisement
Guest User

Untitled

a guest
Nov 7th, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.94 KB | None | 0 0
  1. musics={}
  2. users=[]
  3. score=0
  4. def login():
  5.     cusername="a"
  6.     cpassword="123"
  7.     input("PRESS ENTER TO START ")
  8.     username=input("USERNAME: ")
  9.     password=input("PASSWORD: ")
  10.     while  password!=cpassword or username!=cusername:    
  11.         if username!=cusername:
  12.             print("INVALID USERNAME ")
  13.         if  password!=cpassword:
  14.             print("INVALID PASSWORD")
  15.         createusername=input("WOULD YOU LIKE TO CREATE A NEW ACCOUNT??? ")
  16.         if createusername== "yes" or createusername== "Yes" or createusername== "YES":
  17.             cusername=input("WHAT WOULD YOU LIKE YOUR NEW USERNAME TO BE??? ")
  18.             cpassword=input("WHAT WOULD YOU LIKE YOUR NEW PASSWORD TO BE??? ")
  19.         elif createusername!= "yes" or createusername!= "Yes" or createusername!= "YES":
  20.             print("Redirecting...")
  21.         username=input("USERNAME: ")
  22.         password=input("PASSWORD: ")
  23.     print("WELCOME",username)
  24.  
  25. def load():
  26.     musicfile=open("musicfile.txt","r")
  27.     #print(musics)
  28.     for line in musicfile:
  29.         parts=line.split(",")
  30.         #creates a dictionary entry for each student – last element in list needs the escape character removing
  31.         musics[str(parts[0])]=parts[1],parts[2].strip("\n")
  32.     musicfile.close()
  33.     #print(musics)
  34. def loaduser1():
  35.     userfile=open("userfile.txt","r")
  36.     #print(users)
  37.     for line in userfile:
  38.         parts=line.split(",")
  39.         #creates a dictionary entry for each student – last element in list needs the escape character removing
  40.         users.append((parts[0],int(parts[1])))    
  41.     userfile.close()
  42.     List=users
  43.     sortedlist=sorted(List,key=lambda x:x[1], reverse= True)
  44.     #print("  L  E  A  D  E  R  B  O  A  R  D  ")
  45.     for k in range (5):
  46.         position=k+1 #+1 because it starts on 0
  47.         player=sortedlist[k][0]
  48.         score=sortedlist[k][1]
  49.      #   print("          "+str(position)+". "+player+" = "+str(score))
  50.        
  51. def loaduser():
  52.     userfile=open("userfile.txt","r")
  53.     #print(users)
  54.     for line in userfile:
  55.         parts=line.split(",")
  56.         #creates a dictionary entry for each student – last element in list needs the escape character removing
  57.         users.append((parts[0],int(parts[1])))    
  58.     userfile.close()
  59.     List=users
  60.     sortedlist=sorted(List,key=lambda x:x[1], reverse= True)
  61.     print("  L  E  A  D  E  R  B  O  A  R  D  ")
  62.     for k in range (5):
  63.         position=k+1 #+1 because it starts on 0
  64.         player=sortedlist[k][0]
  65.         score=sortedlist[k][1]
  66.         print("          "+str(position)+". "+player+" = "+str(score))
  67. def start():
  68.     input("WELCOME TO THE GAME PRESS ENTER TO START")
  69.     input("YOU HAVE TO GUESS WHAT SONG IT IS BY ONLY SEEING THE FIRST LETTER ")
  70.     input("THERE ARE 5 SONGS OF WHICH YOU GET 2 CHANCES TO GUESS RIGHT ")
  71.     input("YOU WILL GET A SCORE OUT OF 10 DEPENDING ON HOW MANY GUESSES IT TAKES FOR YOU TO ANSWER CORRECTLY")
  72.  
  73. def play():
  74.     score=0
  75.     print("FINISH THE SONG TITLE")
  76.     for Qu in musics:
  77.         sort=(Qu+" "+musics[Qu][0]+" "+musics[Qu][1])
  78.         #print(sort)#prints artist and song just for testing purposes
  79.         track=musics[Qu][0] #writes the song as the track
  80.         trackwords=track.split(" ") #splits the track into their separate words
  81.         question="" #createsa a blank question
  82.         for word in trackwords:
  83.             question=question+(word[0])+"___ " #adds the first letter of each word each time the loop runs until it runs out of words
  84.         artist=musics[Qu][1] #writes the artist as the artist
  85.         ans1=input(question+" by "+artist+": ") #prints the song with only the first letter of each word and prints the artist out
  86.         if ans1==track:
  87.             #this statement checks whether they got the song  right
  88.             print("SMASHED IT YOU GOT IT RIGHT ")
  89.             print ("Score=",score,"+3pts")
  90.             score=score+3
  91.             print("Your Score is now ",score)
  92.         else:
  93.             print("UNLUCKY YOU GOT IT WRONG!!! TRY AGAIN")
  94.             ans1=input(question+" by "+artist+": ") #prints the song with only the first letter of each word and prints the artist out
  95.             if ans1==track:
  96.                 print("SMASHED IT YOU GOT IT RIGHT ")
  97.                 print ("Score=",score,"+1pts")
  98.                 score=score+1
  99.                 print("Your Score is now ",score)
  100.             else:
  101.                 print("UNLUCKY YOU GOT IT WRONG!!! AGAIN")
  102.                 print("The song is "+track)
  103.                 print ("Score=",score,"+0pts")
  104.                 score=score+0
  105.                 print("Your Score is still ",score)
  106.     print("THANK YOU FOR PLAYING ")
  107.     playername=input("ENTER NAME TO BE SAVED TO LEADERBOARD ")
  108.     users.append((playername,score))
  109.    
  110. def save():
  111.     userfile=open("userfile.txt","w")
  112.     for user in users:
  113.         userfile.write(user[0]+","+ str(user[1])+"\n")
  114.     userfile.close()
  115.  
  116.  
  117.  
  118. login()
  119. load()
  120. loaduser1()
  121. start()
  122. play()
  123. #save()
  124. loaduser()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement