Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys, os, random, csv
- def welcome():
- print ("#####################################")
- print ("# .::Welcome to The Music Quiz::. #")
- print ("# .:Version 1:. #")
- print ("#####################################")
- print ("")
- Choice = input('Do you want to login or register? ')
- Choice = Choice.lower()
- if Choice == 'login':
- login()
- elif Choice == 'register':
- register()
- else:
- print ('Enter login or register')
- def register():
- print ('Follow the register instructions')
- username_check = False
- while username_check == False:
- username = input('Please enter a Username: ')
- with open('users.csv') as csvfile:
- reader = csv.reader(csvfile)
- for row in reader:
- if username == row[0]:
- print ('Username not available, try again.')
- username_check = False
- else:
- username_check = True
- if username_check == True:
- password_check = False
- while password_check == False:
- password = input('Please enter a Password: ')
- score = "0"
- account = username + ',' + password + ',' + score + '\n'
- with open('users.csv', "a") as f:
- for row in account:
- f.write(row)
- print ("Thank You for Registering, You can now login")
- print ("")
- login()
- def login():
- logged_in = False
- while logged_in == False:
- username = input('Please enter your Username ')
- password = input('Please enter your Password ')
- database = open('users.csv')
- users = csv.reader(database)
- for row in users:
- if username == row[0] and password == row[1]:
- logged_in = True
- print ('Logged in successfully as ' + username)
- print ("")
- database = open('users.csv')
- users = csv.reader(database)
- for row in users:
- if username == row[0]:
- currentScore = row[2]
- currentScore = int((currentScore))
- song_list = ''
- song_name = ''
- artist_name = ''
- song_letters = ''
- chances = 2
- score = 0
- quiz = True
- with open('songs.csv', 'rt') as f:
- reader = csv.reader(f)
- song_list = list(reader)
- print ("Your Highest Score is " + str(currentScore))
- print ("Can you beat it?")
- print ("")
- while quiz == True:
- if chances == 2:
- Song = (random.choice(song_list))
- Song = str(Song)
- Song.split(",")
- artist_name,song_name = Song.split(",")
- for char in "']":
- song_name = song_name.replace(char,'')
- for char in "['":
- artist_name = artist_name.replace(char,'')
- song_name.lower()
- print ("You Have " + str(chances), "chances remaining!")
- print ("The Artist of the song is " + artist_name )
- words = song_name.split()
- song_letters = [word[0] for word in words]
- print ("The first letter of each word in the song name are " + str(song_letters))
- guess = input ("What is the name of the song? ")
- guess = guess.lower()
- if guess == song_name:
- print ("Correct the Song was " + song_name, "by " + artist_name)
- score = score + 3
- print ("")
- print ("You scored 3 points for guessing the song the first try")
- else:
- print ("That is incorrect, Try again")
- print ("You have 1 chance left!")
- chances = chances - 1
- guess = input ("What is the name of the song? ")
- guess = guess.lower()
- if guess == song_name:
- print ("Correct the Song was " + song_name, "by " + artist_name)
- score = score + 1
- print ("")
- print ("You scored 1 point for guessing the song the second try")
- chances = 0
- chances = 2
- else:
- print ("")
- print ("You have run out of lives!")
- print ("You Scored " + str(score), " points")
- if int(score) > int(currentScore):
- currentscore = score
- quiz = False
- else:
- logged_in = False
- print ('One or more details are incorrect, Try Again')
- welcome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement