Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import linecache
- import random
- global validation
- validation = False
- global usernamefile
- usernamefile = open("usernames.txt")
- global playernumber
- playernumber = 1
- global pwget
- pwget = linecache.getline("passwords.txt", playernumber)
- global nameget
- nameget = linecache.getline("usernames.txt", playernumber)
- global pwcheck
- pwcheck = str(pwget[:-1])
- global namecheck
- namecheck = str(nameget[:-1])
- global linestotal
- linestotal = (len(usernamefile.readlines()))
- while validation == False:
- playernumber = 1
- print("To login to the system, you need to enter a correct username and password.")
- username = input("Please enter your username.")
- password = input("Please enter your password.")
- while playernumber < (linestotal + 1) and validation == False and username == namecheck and password == pwcheck:
- validation = True
- break
- else:
- for i in range(1, linestotal):
- playernumber +=1
- if username == namecheck and password == pwcheck:
- break
- else:
- nameget = linecache.getline("usernames.txt", playernumber)
- pwget = linecache.getline("passwords.txt", playernumber)
- namecheck = str(nameget[:-1])
- pwcheck = str(pwget[:-1])
- if username == namecheck and password == pwcheck:
- validation = True
- break
- #READ PASSWORD AND USERNAME FROM A TEXT FILE!
- global score
- score = 0
- global IDlist
- IDlist = []
- global f
- f = open("songname.txt")
- global totallines
- totallines = (len(f.readlines()))
- global numberofsongs
- numberofsongs = 0
- print("------------------------------------------------------------")
- for i in range(1,totallines):
- randomID = str(random.randint(1,totallines))
- randID = int(randomID)
- #print(randID)
- while randID in IDlist and len(IDlist) < totallines + 1:
- randomID = str(random.randint(1,totallines))
- randID = int(randomID)
- IDlist.append(randID)
- #print(IDlist)
- songartist = linecache.getline("songartists.txt", randID)
- songname = linecache.getline("songname.txt", randID)
- words = songname.split()
- letters = [word[0] for word in words]
- #print ("".join(letters))
- numberofsongs += 1
- print("The artist is: " + songartist)
- if len(songname.split()) == 1:
- print("The song name is 1 word. The first two letters are: " + songname[0] + songname[1] + ".")
- else:
- print("The song is " + str(len(letters)) + " words long. The first letters in each word are: " + " ".join(letters))
- guess = input("Can you guess the song name?")
- #numberofsongs += 1
- global answer
- answer = False
- global tries
- tries = 0
- while tries != 1:
- if str(songname[:-1].lower()) == str(guess.lower()):
- print("Your guess was correct!")
- answer = True
- print("------------------------------------------------------------")
- break
- else:
- guess = input("Try again")
- print("------------------------------------------------------------")
- tries += 1
- if str(songname[:-1].lower()) == str(guess.lower()):
- answer = True
- else:
- answer = False
- if answer == True and tries == 0:
- score += 3
- elif answer == True and tries == 1:
- print("Your guess was correct!")
- score += 1
- elif answer == False and tries == 1:
- print("Your guess was wrong!")
- print("The song was: " + songname[:-1])
- print("------------------------------------------------------------")
- break
- print("The game is over!")
- print("Your scored " + str(score) + "/" + str(numberofsongs*3) + " points!")
- if score == numberofsongs*3:
- print("You got a perfect score!")
- else:
- print("You guessed: " + str(numberofsongs - 1) + " songs correctly!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement