Project File
Project File
Online
Quiz Game
Index
password="123456",database="kbc")
def signup():
mycursor=mydb.cursor()
nm=input("Enter user name:")
pas=input("Enter Password:")
em=input("Confirm Password:")
if pas==em:
mycursor.execute("insert
into user(username,password)
values('{}','{}')".format(nm,pas))
mydb.commit()
print(mycursor.rowcount,"Id
Created")
else:
print("Password does not
match")
main()
def login():
mycursor=mydb.cursor()
nm=input("Enter user name:")
pas=input("Enter Password:")
mycursor.execute("select *
from user where username='{}'
and password='{}'".format(nm,pas))
myrecords=mycursor.fetchone()
global user
user=myrecords[1]
print("Welcome to game:
",myrecords[1])
start=input("Press 'Y' to start
game and any other key to log
out:")
if start=="Y":
print("Let's Start")
game()
else:
print("Thanks for visiting us,
You are log out")
def score():
mycursor=mydb.cursor()
mycursor.execute("Select *
from user")
myrecords=mycursor.fetchal
l()
print("Name \t Score")
for i in myrecords:
print(i[1],'\t',i[3])
print("Total number of rows
retrieved",mycursor.rowcou
nt)
main()
def game():
mycursor=mydb.cursor()
mycursor.execute("Select * from
mcq")
score=0
i=1
while i<=5:
myrecords=mycursor.fetchone()
print("Question",myrecords[0],":",myr
ecords[1])
print("Options")
print(myrecords[2])
print(myrecords[3])
print(myrecords[4])
print(myrecords[5])
ans=input("Enter correct option:")
if ans== myrecords[6]:
print("Correct Answer")
score=score+10
print("Points:",score)
else:
print("Wrong Answer")
print("Points:",score)
i=i+1
mycursor.execute("update user set
score={} where
username='{}'".format(score,user))
mydb.commit()
if score==50:
print("You win")
else:
a=input("Press Y to play again or N
to main menu:")
if a=="Y":
game()
else:
main()
def main():
print("\nWelcome to Online Quiz
Game")
print("1.New Account \n2.Log
in\n3.Check your Score")
ch=int(input("Enter your Choice:"))
if ch==1:
signup()
elif ch==2:
login()
elif ch==3:
score()
else:
print("Enter correct choice")
main()
main()
Output:
Main menu:
Website
http://python.mykvs.in/index.php
https://www.google.co.in/