Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random,csv
- with open("Songs.csv","r",newline='') as csvfile:
- songs = [i for i in csv.reader(csvfile, delimiter=',')]
- def main(userPosFile):
- score = 0
- playing = True
- while playing:
- song = random.choice(songs)
- print("\nThe first letter of each word in the song is",*[i[0] for i in song[0].split()],"\nThe artist is",song[1])
- for i in range(2):
- if input("\nEnter your guess of what the song might be: ").upper() == song[0].upper():
- if i == 0:
- print("Correct, you get 3 points.")
- score += 3
- else:
- print("Correct, you get 1 point.")
- score += 1
- break
- else:
- print("Inccorect guess.")
- else:
- print("\nYou ran out of guesses and lose.\nYou scored ",score)
- finish(score,userPosFile)
- playing = False
- leader()
- def finish(score, pos):
- if int(scores[pos][2]) < score:
- scores[pos][2] = score
- with open("Scores.csv","w",newline='') as csvfile:
- csv.writer(csvfile, delimiter=",").writerows(scores)
- else:
- print("You have not beaten your previous high score of",scores[pos][2])
- def login():
- global scores
- with open("Scores.csv","r",newline='') as csvfile:
- scores = [i for i in csv.reader(csvfile, delimiter=',')]
- name = input("Enter/Create Username: ")
- for i in range(len(scores)):
- if scores[i][0] == name:
- if input("Enter password: ") == scores[i][1]:
- print("Correct. Logging in...")
- main(i)
- break
- else:
- print("Incorrect details. Try again.\n")
- login()
- break
- else:
- if input("User not found would you like to create an account? (y/n) ") == "y":
- with open("Scores.csv","a",newline='') as csvfile:
- csv.writer(csvfile, delimiter = ",").writerow([name,input("Create password: "),0])
- print("Login in with your new account.\n")
- login()
- def leader():
- l = sorted(scores, key = lambda x:int(x[2]), reverse = True)
- if len(l) <5:
- length = len(l)
- else:
- length = 5
- print("\nThe leaderboard is as follows: ")
- [print("- Position",i+1,l[i][0],"with a score of",l[i][2]) for i in range(length)]
- login()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement