Advertisement
Guest User

Untitled

a guest
Dec 14th, 2018
650
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.96 KB | None | 0 0
  1. import linecache
  2. import random
  3. global validation
  4. validation = False
  5. global usernamefile
  6. usernamefile = open("usernames.txt")
  7. global playernumber
  8. playernumber = 1
  9. global pwget
  10. pwget = linecache.getline("passwords.txt", playernumber)
  11. global nameget
  12. nameget = linecache.getline("usernames.txt", playernumber)
  13. global pwcheck
  14. pwcheck = str(pwget[:-1])
  15. global namecheck
  16. namecheck = str(nameget[:-1])
  17. global linestotal
  18. linestotal = (len(usernamefile.readlines()))
  19. while validation == False:
  20. playernumber = 1
  21. print("To login to the system, you need to enter a correct username and password.")
  22. username = input("Please enter your username.")
  23. password = input("Please enter your password.")
  24. while playernumber < (linestotal + 1) and validation == False and username == namecheck and password == pwcheck:
  25. validation = True
  26. break
  27. else:
  28. for i in range(1, linestotal):
  29. playernumber +=1
  30. if username == namecheck and password == pwcheck:
  31. break
  32. else:
  33. nameget = linecache.getline("usernames.txt", playernumber)
  34. pwget = linecache.getline("passwords.txt", playernumber)
  35. namecheck = str(nameget[:-1])
  36. pwcheck = str(pwget[:-1])
  37. if username == namecheck and password == pwcheck:
  38. validation = True
  39. break
  40. #READ PASSWORD AND USERNAME FROM A TEXT FILE!
  41.  
  42. global score
  43. score = 0
  44. global IDlist
  45. IDlist = []
  46. global f
  47. f = open("songname.txt")
  48. global totallines
  49. totallines = (len(f.readlines()))
  50. global numberofsongs
  51. numberofsongs = 0
  52. print("------------------------------------------------------------")
  53. for i in range(1,totallines):
  54. randomID = str(random.randint(1,totallines))
  55. randID = int(randomID)
  56. #print(randID)
  57. while randID in IDlist and len(IDlist) < totallines + 1:
  58. randomID = str(random.randint(1,totallines))
  59. randID = int(randomID)
  60. IDlist.append(randID)
  61. #print(IDlist)
  62. songartist = linecache.getline("songartists.txt", randID)
  63. songname = linecache.getline("songname.txt", randID)
  64.  
  65. words = songname.split()
  66. letters = [word[0] for word in words]
  67. #print ("".join(letters))
  68. numberofsongs += 1
  69. print("The artist is: " + songartist)
  70. if len(songname.split()) == 1:
  71. print("The song name is 1 word. The first two letters are: " + songname[0] + songname[1] + ".")
  72. else:
  73. print("The song is " + str(len(letters)) + " words long. The first letters in each word are: " + " ".join(letters))
  74. guess = input("Can you guess the song name?")
  75. #numberofsongs += 1
  76. global answer
  77. answer = False
  78. global tries
  79. tries = 0
  80. while tries != 1:
  81. if str(songname[:-1].lower()) == str(guess.lower()):
  82. print("Your guess was correct!")
  83. answer = True
  84. print("------------------------------------------------------------")
  85. break
  86. else:
  87. guess = input("Try again")
  88. print("------------------------------------------------------------")
  89. tries += 1
  90. if str(songname[:-1].lower()) == str(guess.lower()):
  91. answer = True
  92. else:
  93. answer = False
  94. if answer == True and tries == 0:
  95. score += 3
  96. elif answer == True and tries == 1:
  97. print("Your guess was correct!")
  98. score += 1
  99. elif answer == False and tries == 1:
  100. print("Your guess was wrong!")
  101. print("The song was: " + songname[:-1])
  102. print("------------------------------------------------------------")
  103. break
  104.  
  105.  
  106. print("The game is over!")
  107. print("Your scored " + str(score) + "/" + str(numberofsongs*3) + " points!")
  108. if score == numberofsongs*3:
  109. print("You got a perfect score!")
  110. else:
  111. print("You guessed: " + str(numberofsongs - 1) + " songs correctly!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement