0% found this document useful (0 votes)
6 views3 pages

Quiz Conduction

Uploaded by

siprasamanta416
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views3 pages

Quiz Conduction

Uploaded by

siprasamanta416
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

import sys

import datetime
import mysql.connector
import matplotlib.pyplot as plt
import random
mydb=mysql.connector.connect(host="localhost", user="root",
password="abhisek",database="brain_teaser")
mycursor=mydb.cursor()
# Function definition for Home screen
def Home():
f=1
while(f!=3):
print("WELCOME TO QUIZ GAMING")
print("********************")
print("1. ADD QUESTIONS")
print("2. CONDUCT QUIZ SESSIONS")
print("3. CHECK SCOREBOARD")
print("4. NAME-SCORE ANALYSIS")
print("5. EXIT")
f=int(input("ENTER YOUR CHOICE: "))
if(f==1):
Question()
elif(f==2):
Quiz()
elif(f==3):
Scoreboard()
elif(f==4):
Graph()
elif(f==5):
print("CLOSING THE QUIZ GAME")
mycursor.close()
mydb.close()
sys.exit()
else:
Home()

def Question():
ch='Y'
while ch=='Y' or ch=='y':
print("WELCOME TO QUESTION PORTAL")
print("***********************")
q=input("ENTER THE QUESTION :")
op1=input("ENTER THE OPTION 1 :")
op2=input("ENTER THE OPTION 2 :")
op3=input("ENTER THE OPTION 3 :")
op4=input("ENTER THE OPTION 4 :")
ans=0
while(ans==0):
op=int(input("WHICH OPTION IS THE CORRECT ANSWER?(1,2,3,4) :"))
if(op==1):
ans=op1
elif(op==2):
ans=op2
elif(op==3):
ans=op3
elif(op==4):
ans=op4
else:
print("PLEASE CHOOSE THE CORRECT OPTION AS ANSWER")
mycursor.execute("Select * from question")
data=mycursor.fetchall()
qid=(mycursor.rowcount)+1
mycursor.execute("Insert into question values(%s,%s,%s,%s,%s,%s,%s)",
(qid,q,op1,op2,op3,op4,ans))
mydb.commit()
ch=input("QUESTION ADDED SUCCESSFULLY. DO YOU WANT TO ADD MORE?(Y/N):")
Home()
# Function definition for Quiz
def Quiz():
print("LETS START THE QUIZ")
print("***********************")
mycursor.execute("Select * from question")
data=mycursor.fetchall()
name=input("ENTER YOUR FULL NAME :")
rc=mycursor.rowcount
noq=int(input("ENTER THE NUMBER OF QUESTIONS TO ATTEMPT (MAX %s):"%rc))
l=[]
while(len(l)!= noq):
x=random.randint(1,rc)
if(l.count(x)>0):
l.remove(x)
else:
l.append(x)
print("QUIZ HAS STARTED")
c=1
score = 0
for i in range(0,len(l)):
mycursor.execute("Select * from question where qid=%s",(l[i],))
ques=mycursor.fetchone()

print("----------------------------------------------------------------------------
----------------")
print("Q.",c,":",ques[1],"\nA.",ques[2],"\t\tB.",ques[3],"\nC.",ques[4],"\
t\tD.",ques[5])

print("----------------------------------------------------------------------------
----------------")
c += 1
ans=None
while(ans==None):
choice=input("Answer (A,B,C,D) :")
if(choice=='A' or choice=='a'):
ans=ques[2]
elif(choice=='B' or choice=='b'):
ans=ques[3]
elif(choice=='C' or choice=='c'):
ans=ques[4]
elif(choice=='D' or choice=='d'):
ans=ques[5]
else:
print("KINDLY SELECT A,B,C,D AS OPTION ONLY")
if(ans==ques[6]):
print("YOUR ANSWER IS CORRECT")
score=score+1
else:
print("INCORRECT ANSWER...CORRECT ANSWER IS:",ques[6])
print("\n\n\nQUIZ HAS ENDED.",name,"YOUR FINAL SCORE IS:",score)
sql="insert into user(name,date_play,score)values(%s,%s,%s)"
d=datetime.datetime.today()
value=(name,d,score)
mycursor.execute(sql,value)
mydb.commit()
input("PRESS ANY KEY TO CONTINUE")

def Scoreboard():
nm=input("\nENTER THE NAME OF THE USER WHOSE SCORE TO VIEW:")
sql="Select * from User where name=%s"
value=(nm,)
mycursor.execute(sql,value)
rec=mycursor.fetchall()
if(len(rec)==0):
print('NO SUCH USER EXISTS')
else:
print('NAME','\t','DATE','\t\t','SCORE')
for info in rec:
print(info[0],'\t',info[1],'\t',info[2])
Home()

def Graph():
sql='Select * from user'
mycursor.execute(sql)
T=mycursor.fetchall()
L1=[]
for x in T:
L1.append(x[0])
L2=[]
for x in T:
L2.append(x[2])
plt.bar(L1,L2)
plt.xlabel('NAME')
plt.ylabel('SCORE')
plt.title('NAME SCORE ANALYSIS')
plt.show()
Home()

Home()

You might also like