Advertisement
Guest User

joshhhhhhhhhhh

a guest
Dec 12th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. #Ryan Spurrier 18401 5403
  2. import random
  3. #2D Array to store the users and passwords when the program is running
  4. usersArray = []
  5. songsAndArtistsArray = []
  6.  
  7. def loadFile():
  8. usersFile = open("users.txt", "r")
  9.  
  10. for line in usersFile:
  11. user = []
  12. user = line.split(",")
  13.  
  14. user[len(user)-1] = user[len(user)-1].strip("\n")
  15.  
  16. usersArray.append(user)
  17.  
  18. usersFile.close()
  19.  
  20. songsFile = open("songsAndArtists.txt", "r")
  21.  
  22.  
  23. for line in songsFile:
  24. song = []
  25. song = line.split(",")
  26.  
  27. song[len(song)-1] = song[len(song)-1].strip("\n")
  28.  
  29. songsAndArtistsArray.append(song)
  30.  
  31. songsFile.close()
  32.  
  33. print(songsAndArtistsArray)
  34.  
  35. def signUp():
  36. #Ask the user for their name
  37. firstName = input("Please enter your first name\n")
  38. surname = input("Please enter your surname\n")
  39.  
  40. #Generate the first part of the username
  41. username = firstName + surname
  42.  
  43. #Concatenate 3 random numbers at the end
  44. counter = 0
  45. while counter < 3:
  46. randomNumber = random.randint(0,9)
  47. username = username + str(randomNumber)
  48. counter = counter + 1
  49.  
  50. #Ask for the password two times
  51. password = input("Please enter your password\n")
  52. password1 = input("Please re-enter your password\n")
  53.  
  54. #Continue the program if the passwords match
  55. if password == password1:
  56. print("Passwords match")
  57. else:
  58. print("Passwords don't match")
  59. exit()
  60.  
  61. print("Your username is " + username + " please make a note of this")
  62.  
  63. user = []
  64. user.append(username)
  65. user.append(password)
  66. usersArray.append(user)
  67. print(usersArray)
  68.  
  69. usersFile = open("users.txt", "w")
  70.  
  71. for user in usersArray:
  72. lineForFile = ""
  73.  
  74. for item in user:
  75. if item == user[len(user)-1]:
  76. lineForFile = lineForFile + item + "\n"
  77. else:
  78. lineForFile = lineForFile + item + ","
  79.  
  80. print(lineForFile)
  81. usersFile.write(lineForFile)
  82.  
  83. usersFile.close()
  84.  
  85. def login():
  86.  
  87. loggedIn = False
  88.  
  89. while not loggedIn:
  90.  
  91. enteredUsername = input("Enter your username\n")
  92. enteredPassword = input("Enter your password\n")
  93.  
  94. for user in usersArray:
  95. if enteredUsername == user[0] and enteredPassword == user[1]:
  96. print("Login sucessful")
  97. loggedIn = True
  98.  
  99. if not loggedIn:
  100. print("username or password incorrect")
  101.  
  102. return loggedIn
  103.  
  104.  
  105.  
  106.  
  107.  
  108. '''Main Program'''
  109.  
  110. loadFile()
  111.  
  112. running = True
  113.  
  114. while running:
  115.  
  116. menuChoice = input("Menu: \n1. Sign up\n2. Login\n")
  117.  
  118. if menuChoice == "1":
  119. signUp()
  120. elif menuChoice == "2":
  121. if login() == True:
  122. randomNumber = random.randint(0,len(songsAndArtistsArray)-1)
  123. randomlyChosenSong = songsAndArtistsArray[randomNumber]
  124. print("Guess the name of the song")
  125. print("Artist: " + randomlyChosenSong[1])
  126. songNameSplit = randomlyChosenSong[0].split(" ")
  127.  
  128. lineToPrint = ""
  129.  
  130.  
  131.  
  132. for word in songNameSplit:
  133. lineToPrint = lineToPrint + word[0]
  134.  
  135. print(lineToPrint)
  136.  
  137. pointsOnOffer = 3
  138.  
  139. for i in range(0,2):
  140. userGuess = input("What is the name of the song?\n")
  141. if userGuess == randomlyChosenSong[0]:
  142. print("Correct")
  143. userScore = pointsOnOffer
  144. correct = True
  145. break
  146.  
  147. pointsOnOffer = 1
  148. print(str(userScore))
  149. print(randomlyChosenSong)
  150. pass
  151. else:
  152. exit()
  153.  
  154. answer = input("Do you want to run the program again? y/n\n")
  155.  
  156. if answer == "y":
  157. running = True
  158. elif answer == "n":
  159. running = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement