Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import csv
- import sqlite3
- from random import choice
- connection = sqlite3.connect('users.db')
- cursor = connection.cursor()
- def welcome():
- print("#####################################")
- print("# .::Welcome to The Music Quiz::. #")
- print("# .:Version 1:. #")
- print("#####################################")
- print("")
- option = input('Do you want to login or register? ')
- option = option.lower()
- if option == 'login':
- login()
- elif option == 'register':
- register()
- else:
- print('Enter login or register')
- def register():
- sql = '''CREATE TABLE IF NOT EXISTS Players
- (PID INTEGER PRIMARY KEY AUTOINCREMENT,
- USERNAME VARCHAR(100),
- PASSWORD VARCHAR(100),
- SCORE INT)'''
- cursor.execute(sql)
- print('Follow the register instructions')
- username_check = False
- while username_check == False:
- tempusername = input('Please enter a Username: ')
- cursor.execute('''SELECT username FROM Players WHERE username=?''', (tempusername,))
- exists = cursor.fetchall()
- if not exists:
- username_check = True
- else:
- print('Username not available, try again.')
- username_check = False
- if username_check == True:
- password_check = False
- while password_check == False:
- temppassword = input('Please enter a Password: ')
- tempscore = "0"
- params = (tempusername, temppassword, tempscore)
- cursor.execute("INSERT INTO Players VALUES (NULL, ?, ?, ?)", params)
- cursor.execute(sql)
- connection.commit()
- 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 ')
- cursor.execute('SELECT * from Players WHERE username="%s" AND password="%s"' % (username, password))
- if cursor.fetchone() is not None:
- logged_in = True
- print('Logged in successfully as ' + username)
- print("")
- cursor.execute('SELECT score from Players WHERE username="%s"' % (username))
- currentScore = cursor.fetchall()
- currentScore = [x[0] for x in 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 = (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 str((score)) > str((currentScore)):
- currentscore = score
- cursor.execute('''UPDATE Players SET score = ? WHERE username =?''', (username, score))
- connection.commit()
- connection.close()
- 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