0% found this document useful (0 votes)
188 views20 pages

Quiz Project

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

Quiz Project

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

Project on: Quiz Program

QUIZ PROGRAM
INDEX

Sr. No Particular
1 Brief overview of project
2 Software and hardware requirement
3 Structure of the tables
4 Source code of project
5 Output screening
6 Bibliography

Brief overview of project


Project Idea: Quiz Application
Project Description
The Quiz Master is a Python-based application that serves as an interactive
quiz management system, providing both users and administrators with the
ability to engage in quizzes and manage quiz questions.

It establishes a connection to a local MySQL database, 'quiz', and creates two


essential tables: 'questions' for storing quiz questions and options and
'high_scores' for recording player names, scores, and timestamps of high
scores. The program offers a range of features, including the ability for users
to take quizzes with up to 10 randomly selected questions, view their scores,
and compete for high scores. Users navigate the system through a user-
friendly main menu, making choices to start quizzes, view high scores,
access an admin panel, or exit the program. The admin panel provides
administrators with tools to add, edit, and delete quiz questions, ensuring
the content remains dynamic. Additionally, administrators can view all the
existing questions.

Sample Output

Key Features of Quiz Master

Before you start designing your program, it's crucial to have a clear
understanding of the problem you're trying to solve. Let's revisit the key
features of our Quiz Master Application:

1. Quiz Module:

 Users can start a quiz by choosing the "Start Quiz" option from the
main menu.
 The quiz module fetches up to 10 random questions from the MySQL
database.
 Users are presented with multiple-choice questions and must select
the correct answer by entering the corresponding number (1, 2, 3, or
4).
 The user's score is calculated based on the number of correct answers.
 At the end of the quiz, the user's score is displayed.

2. High Scores:

 Users can view the top 10 high scores by choosing the "High Scores"
option from the main menu.
 High scores are retrieved from the MySQL database and displayed,
including the player's name, score, and timestamp.

3. Admin Panel:

 An admin panel allows authorized users to manage quiz questions.


 Admins must authenticate themselves with a username and password.
 Once authenticated, admins have access to the following options:
o Add Question: Add a new multiple-choice question to the quiz
database.
o Edit Question: Modify an existing question, including its options
and correct answer.
o Delete Question: Remove a question from the quiz database.
o View All Questions: Display a list of all questions currently in the
database.

How To Code The Project

To make your project organized and manageable, it's essential to divide your
code into smaller functions, each with a specific purpose and responsibility.

Begin with the most basic functionalities, Once these are working, gradually
add more features. Don't hesitate to ask for help or guidance from
instructors, classmates, or online communities. If you find making this
project is too complex, this sample project might be useful for you.

Prerequisites

Before you begin, make sure you have the following installed:
Python: Download Python
MySQL: Download MySQL
mysql-connector-python: install it using pip

pip install mysql-connector-python

Software and hardware requirement:


Technologies Used:

SOFTWARE SPECIFICATION:-
Operating System : Windows 7
Platform : Python IDLE 2.7
Database : MySQL
Languages : Python

HARDWARE SPECIFICATION:-
Processor : Dual Core and above
Hard Disk : 40GB
Ram : 1024 MB

Data file handling has been effectively used in the program. The database is a
collection of interrelated data to serve multiple applications. That is database
programs create files of information. So we see that files are worked with most,
inside the program.

DBMS: The software required for the management of data is called as DBMS.
It has3 models:

• Relation model

• Hierarchical model

• Network model

RELATIONAL MODEL: It’s based on the concept on relation. Relation is the


table that consists of rows and columns. The rows of the table are called tuple
and the columns of the table are called attribute. Numbers of rows in the table is
called as cardinality. Number of columns in the table is called as degree.

HIERARCHICAL MODEL: In this type of model, we have multiple records for


each record. A particular record has one parent record. No chide record can
exist without parent record. In this, the records are organized in tree.

NETWORK MODEL: In this, the data is represented by collection of records


and relationship is represented by (ink or association.

CHARACTERISTICS OF DBMS:
• It reduces the redundancy
• Reduction of data in inconsistency
• Data sharing
• Data standardization
DIFFERENT TYPES OF FILES: -BASED ON ACCESS:
• Sequential file
• Serial file
• Random (direct access) file BASED ON STORAGE:-
• Text file
• Binary File

Structure of the tables:


Python code:
Source code:
#create table student(stuid int primary key,sname varchar(20),gender
varchar(20),school varchar(50));
#create table login (stuid int ,password varchar(20),foreign key login(stuid)
references student(stuid));
#create table questions(qid int primary key auto_increment,question
varchar(1000),subject varchar(20),type1 int);
# create table result(stuid int,score int,subject varchar(20),total_ques int,foreign
key result(stuid) references student(stuid));

import mysql.connector
import random
import datetime
def view_stu_result(stu):

mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
cur=mycon.cursor()
qry="select * from student,result where student.stuid=result.stuid order by score
desc"
cur.execute(qry)
data=cur.fetchall()
for i in data:
if i[0]==stu:
print(i)
mycon.close()

def view_result():

mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
cur=mycon.cursor()
qry="select * from student,result where student.stuid=result.stuid"
cur.execute(qry)
data=cur.fetchall()
for i in data:
print(i)
mycon.close()

def start_quiz(stuid,level,subject,doq):

mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
cur=mycon.cursor()
qry="select * from questions where type1={} and
subject='{}'".format(level,subject)
cur.execute(qry)
data=cur.fetchall()
score=0

print(" no of questions you are qoing to attend",cur.rowcount)


total_ques=cur.rowcount
for i in data:
print(i[1])
print("a)",i[4],"\t","b)",i[5],"\t","c)",i[6],"\t","d)",i[7])
yours=input("enter your answer")
if i[8]==yours:
score+=1
print("your score",score)

qry="insert into result values({},{},'{}','{}',


{})".format(stuid,score,doq,subject,total_ques)
cur.execute(qry)
mycon.commit()
mycon.close()
def add_questions():

mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
cur=mycon.cursor()
#qid=auto_increment
ques=input("Enter the Question")
sub=input("Enter the subject")
sub=sub.upper()
type1=int(input("enter the type"))
op1=input("Option1:`")
op2=input("Option2:`")
op3=input("Option3:`")
op4=input("Option4:`")
ans=input("answer:`")
qry="insert into questions (question,subject,type1,op1,op2,op3,op4,ans)
values('{}','{}',
{},'{}','{}','{}','{}','{}')".format(ques,sub,type1,op1,op2,op3,op4,ans)
cur.execute(qry)
mycon.commit()
mycon.close()

def edit_questions():
mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
cur=mycon.cursor()
qid=int(input("enter the qid"))
choice=int(input("1-change type\n 2-change subject\n3-change question"))
if choice==1:
newtype=int(input("enter the new type"))
qry="update questions set type1={} where qid={}".format(newtype,qid)
cur.execute(qry)
elif choice==2:
newsub=input("enter the new subject")
newsub=newsub.upper()
qry="update questions set subject='{}' where qid={}".format(newsub,qid)
cur.execute(qry)
elif choice==3:
newques=input("enter the question")
qry="update questions set question='{}' where qid={}".format(newques,qid)
cur.execute(qry)
mycon.commit()
mycon.close()

def view_questions():

mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
cur=mycon.cursor()
choice=int(input("1-based on type\n 2-based on subject\n3-exit"))
if choice==1:
t=int(input("enter the type 1 or 2 "))
qry="select * from questions where type1={}".format(t)
elif choice==2:
s=input("enter the subject")
s=s.capitalize()
qry="select * from questions where subject='{}'".format(s)
elif choice==3:
exit()
else:
print("wrong choice")

cur.execute(qry)
data=cur.fetchall()
for i in data:
print(i)
mycon.close()

def delete_questions():

mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
cur=mycon.cursor()
qid=int(input("enter the question_id"))
qry="select qid from questions where qid={}".format(qid)
cur.execute(qry)
data=cur.fetchall()
print(data)
if data[0][0]==None:
print(" No such qid available")
else:
qry="delete from questions where qid={}".format(qid)
cur.execute(qry)
mycon.commit()
mycon.close()

def login_update():

mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
cur=mycon.cursor()
while(True):
uname=int(input("enter the username"))
pwd=input(" enter the old password")
qry="select * from login where username={}".format(uname)
cur.execute(qry)
data=cur.fetchall()
print(data)
if data[0][1]==pwd:
passnew=input(" enter the new password")
qry="update login set password='{}' where
username={}".format(passnew,uname)
cur.execute(qry)
mycon.commit()
print("password successfully updated")
break
cho=input(" do you want to try again? press y/n")
if cho.lower()=='n':
break
mycon.close()

def show_student():

mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
cur=mycon.cursor()
qry="select * from student"
cur.execute(qry)
data=cur.fetchall()
for i in data:
print(i)
mycon.close()

def show_questions():
mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
cur=mycon.cursor()
qry="select * from questions"
cur.execute(qry)
data=cur.fetchall()
for i in data:
print(i)
mycon.close()

def show_login_details():

mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="empmgnt")
cur=mycon.cursor()
qry="select * from login"
cur.execute(qry)
data=cur.fetchall()
for i in data:
print(i)
mycon.close()

#main
mycon=mysql.connector.connect(host="localhost",user="root",password="root",da
tabase="quizdb")
if not mycon.is_connected():
print("connection failure")
else:
cur=mycon.cursor()
while True:
choice=int(input("1-Student Registration\n2-Login\n3.exit"))
if choice==1:
sname=input("Student Name:")
gender=input("Gender:")
school=input("Name of the school")

qry="select max(stuid) from student"


cur.execute(qry)
data=cur.fetchone()
print(data)

if data[0]==None:
stuid=1000
else:
stuid=data[0]+1
qry="insert into student(stuid,sname,gender,school)
values({},'{}','{}','{}')".format(stuid,sname,gender,school)
cur.execute(qry)
mycon.commit()

uname=stuid
password=sname[:4]+str(random.randint(100,10000))
print(" your userid=",uname)
print("your password=",password)
qry="insert into login (stuid,password)
values({},'{}')".format(uname,password)
cur.execute(qry)
mycon.commit()

elif choice==2:
stuid=input("Enter id : ")
password=input("Enter Password : ")
qry="select * from login where stuid={} and
password='{}'".format(stuid,password)
cur.execute(qry)
data=cur.fetchone()
print(data)
if data==None:
print(" Invalid Login")
else:
print("Login successful")

if data[0]==999 and data[1]=="admin":


while(True):
choice=int(input("1-add\n2-edit\n3.view\n4-delete\n5-view_result\
n6.exit"))
if choice==1:
add_questions()#ok
elif choice==2:
edit_questions()#ok
elif choice==3:
view_questions()#ok
elif choice==4:
delete_questions()#ok
elif choice==5:
view_result()
elif choice==6:
exit()#ok
else:
print("Invalid choice")
cho=input("any more?y/n")
if cho.lower()=='n':
break

else:

print('\t*** EMPLOYEES MANAGEMENT SYSTEM ***\n')


print('*'*50)
print("\n1.Quiz\t2-View result\t3.exit")
choice = int(input("Enter Your Choice [1-3] : "))
if choice==1:
level=int(input("enter the level of the quiz 3-hard 2-medium 1-
easy"))
subject=input("Enter subject name")
subject=subject.capitalize()
start_quiz(data[0],level,subject,datetime.datetime.now())
elif choice==2:
view_stu_result(data[0])
elif choice==3:
exit()
else:
print("enter the valid choice")

elif choice==3:
exit()
else:
print(" Invalid choice")

Output Screen:
BIBLIOGRAPHY
1. http://www.google.com/
2. http://en.wikipedia.org

3. Computer science with python

by Sumita Arora

You might also like