Advertisement
666PREDICTIONS666

p. code

Nov 22nd, 2018
625
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.65 KB | None | 0 0
  1. import random
  2. import time
  3.  
  4.  
  5. function signup()
  6.  
  7. username = "admin"
  8. password = "password"
  9.  
  10. username1 = INPUT("What is the username? ")
  11. password1 = INPUT("What is the assword? ")
  12.  
  13. if username1 == username and password == password1:
  14. OUTPUT ("Welcome to the program!")
  15. mainMenu()
  16. elif username1 and password1:
  17. OUTPUT ("Incorrect Username or Password.")
  18. OUTPUT ("Please try again...")
  19. signup()
  20.  
  21. end function
  22.  
  23. function mainMenu()
  24.  
  25. global gamename
  26. gamename = INPUT("What is your name? ")
  27. OUTPUT (" 1) Song Game")
  28. OUTPUT (" 2) Song List")
  29. OUTPUT (" 3) Scoreboard")
  30.  
  31. opt = INPUT("Enter your choice: ")
  32.  
  33. while opt >= 4:
  34. OUTPUT ("That is not a valid option. Please try again...")
  35. opt = INPUT("Enter your choice: ")
  36. if opt == (1):
  37. rand()
  38. elif opt == (2):
  39. OUTPUT ("""
  40. """)
  41. OUTPUT ("Here is the song list; ")
  42. OUTPUT ("It topscore()goes in the order song , artist.")
  43. OUTPUT ("""
  44.  
  45. """)
  46. text_file = open("songs.txt", "r")
  47. OUTPUT (text_file.read())
  48. text_file.close
  49. mainMenu()
  50.  
  51. elif opt == (3):
  52. OUTPUT ("The top 5 players are: ")
  53. topscore()
  54. end while
  55. end function
  56.  
  57. function rand()
  58. array ListName[]
  59. file = open("songs.txt", "r")
  60. for line in file:
  61. ListName.append(line)
  62. end for
  63. file.close()
  64. songchoice(ListName)
  65.  
  66. end function
  67.  
  68. function songchoice(ListName)
  69. guesses = 1
  70. points = 0
  71. chances = 2
  72.  
  73. OUTPUT ("------WELCOME TO THE SONG GUESSING GAME------")
  74. OUTPUT (" ")
  75. OUTPUT (" ")
  76. OUTPUT (" ")
  77. OUTPUT (" ")
  78. OUTPUT ("---------------------------------------------")
  79.  
  80. while chances >0 and len(ListName) >0:
  81.  
  82.  
  83. chances = 2
  84. randomsong = random.choice(ListName)
  85. position = randomsong.find(",")
  86. song = randomsong[:position]
  87. artist = randomsong[position:]
  88.  
  89. OUTPUT (song[0])
  90. OUTPUT (artist)
  91.  
  92. choice = INPUT("Please enter your choice of song ")
  93.  
  94. if choice == song:
  95. OUTPUT ("Well done, you have guessed the song correctly")
  96. points = points+3
  97. OUTPUT ("you have", points, "points!")
  98. ListName.remove(randomsong)
  99. else:
  100. OUTPUT ("Sorry! The song is wrong")
  101. chances = chances-1
  102. choice2 = (INPUT("What is your second attempt?" )
  103. if choice2 == song:
  104. OUTPUT ("Well done, you guessed the second time")
  105. points = points+1
  106. OUTPUT ("You have", points, "points")
  107. ListName.remove(randomsong)
  108. else:
  109. OUTPUT ("You guessed wrong again")
  110. chances = 0
  111. end while
  112. end function
  113.  
  114.  
  115. endgame()
  116.  
  117.  
  118. OUTPUT ("Game over")
  119. OUTPUT ("you have", points, "points")
  120. points = (points)
  121. file = open ("results.txt","a+")
  122. file.write(gamename)
  123. file.write(",")
  124. file.write(points)
  125. file.write("\n")
  126. file.close
  127.  
  128. time.sleep(2)
  129. mainMenu()
  130.  
  131. end function
  132.  
  133.  
  134. function something()
  135. OUTPUT (" ")
  136. OUTPUT (" ")
  137. while chances >0 and len(songList) >0:
  138.  
  139. chances = 2
  140. randomSong = random.choice(songList)
  141. position = randomSong.find("by")
  142. song = randomSong[:position]
  143.  
  144. artist = randomSong[position:]
  145.  
  146. OUTPUT (song[0])
  147. OUTPUT (artist)
  148.  
  149. choice = (INPUT("Please enter the choice of song, remember you only have two chances to guess")
  150.  
  151. end function
  152.  
  153. function topscore()
  154.  
  155. array scoresList[]
  156. file = open("results.txt")
  157. for line in file:
  158. splits = line.split(",")
  159. score = splits[1]
  160. name = splits[0]
  161. score=(score)
  162. scoresList.append([score,name])
  163. end for
  164. for i in range(5):
  165. maximumScore = max(scoresList)
  166. place = i+1
  167. maxname = maximumScore[1]
  168. maxscore = maximumScore[0]
  169. scoresList.remove(maximumScore)
  170. OUTPUT ("Place number",place,"is","'"+maxname+"'","with a score of",maxscore)
  171. OUTPUT ("*********************************************")
  172. OUTPUT ("*********************************************")
  173. OUTPUT ("*********************************************")
  174. end for
  175. end function
  176.  
  177.  
  178. signup()
  179.  
  180. onh
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement