Professional Documents
Culture Documents
Project File Class
Project File Class
Quiz Program
Project Prepared by
NAME – SATVIK FOTEDAR & DEVANSH GIROTRA
CLASS – XII A
1
Index
CERTIFICATE
2
This is to certify that Satvik Fotedar & Devansh Girotra of
class XII, SAM International school, Dwarka, New Delhi
have successfully completed the project in Computer
Science as prescribed by CBSE in the year 2020-21.
Date : -
Signature Signature
(Internal Examiner) (External Examiner)
ACKNOWLEDGEMENT
3
In the present world of competition there is a race of
existence in which, those are having will to come forward,
succeed. With this spirit I took part in this project. First of
all, I would like to thank my parents who have always
supported and encouraged me up to this stage. I feel
proud in thanking my teacher Ms. Anu Joseph without
whose help I would have not been able to complete the
project. I would also like to express my gratitude to Ms
Karuna Verma(Principal , Sam International School) for
blessing me with such a golden opportunity to enhance
my coding skills. I thank everyone from my friends to my
teachers for helping me to accomplish this task.
REQUIREMENTS
Hardware Required
RAM – 1GB or above
Processor – Core™ or i5
4
Hard Disk – 5 GB
SOFTWARE REQUIRED
Operating System – Windows 7 or newer
Python – Version (3.7.9)
SQL – Version (8.0.21)
Microsoft Excel
MySQL Workbench
INTRODUCTION
Python is an open source, interpreted, high-level and general-purpose
programming language. It was created by Guido van Rossum and first
released in 1991 at the National Research Institute for Mathematics ,
Netherlands. It is presently owned by Python Software Foundation (PSF).
It can be used effectively to build any kind of program that does not require
direct access to the computer’s hardware. It was inspired by the famous
BBC comedy show Monty Python’s Flying Circus.
5
Python uses dynamic typing and a combination of reference counting and a
cycle-detecting garbage collector for memory management.[54] It also
features dynamic name resolution (late binding), which binds method and
variable names during program execution.
7
Files imported by the
Program
Random
Sys
MySQL Connector
Datetime
PROGRAM CODE
import random
import sys
import mysql.connector
import ctypes
from datetime import datetime
subject_options=[]
ucode=acursor.rowcount+1
if uname in usernames:
print("Username already taken")
register()
else:
name=str(input("Please enter your name:")).strip()
upwd=str(input("Please enter password:")).strip()
#check password
8
acursor.execute("select ucode from users")
acursor.fetchall()
admin='0'
if ucode==1:
admin='1'
if user=="1":
print()
uname=str(input("Please enter username:")).strip().lower()
upwd=str(input("Please enter password:")).strip()
use_rec1={}
for r in use1:
use_rec1[r[2]]=r[3]
if uname in use_rec1:
if use_rec1[uname]==upwd:
use_rec2={}
for r in use1:
use_rec2[r[2]]=r[1]
User_name=use_rec2[uname]
use_rec3={}
for r in use1:
use_rec3[r[2]]=r[0]
User_code=use_rec3[uname]
use_rec4={}
for r in use1:
use_rec4[r[2]]=r[4]
User_admin=use_rec4[uname]
print()
print("Welcome "+User_name)
9
while mainmenu(User_code,User_name,User_admin):
print()
else:
print("Invalid credentials entered")
loginmenu()
else:
print("Invalid credentials entered")
loginmenu()
elif user=="2":
register()
elif user=="0":
print("Goodbye.")
sys.exit()
else:
print()
print("Invalid Option Entered")
if menuopt=="1":
print()
menu1(User_code,User_name)
elif menuopt=="2":
print()
result(User_code,User_name)
elif menuopt=="3":
print()
password(User_code)
elif menuopt=="4":
print()
print("Thank you for playing")
loginmenu()
elif User_admin==1 and menuopt=="5":
adminmenu(User_code)
elif menuopt=="0":
print()
print("Thank you for playing")
11
sys.exit()
else:
print("Invalid Option Entered")
return True
while True:
print()
print("Are you sure, you want to add this question to the
database?")
print("Y: Yes")
print("N: No")
print()
sure=str(input("Enter your choice: ")).strip().lower()
if sure=='y':
acursor.execute("insert into quiz_bank values ("+str(qcode)+
",'"+scode+"', '"+newq+"','"+opt1+"',
'"+opt2+"','"+opt3+"','"+opt4+"','"+ans+"')")
adb.commit()
print("New question successfully added to the database.")
input("Press enter to continue...")
break
elif sure=='n':
print("Ignoring the question addition")
input("Press enter to continue...")
return
else:
print("Invalid option entered")
print("Add more?")
print("1: Yes")
print("2: No")
print()
addmore=str(input("Enter your choice:")).strip()
if addmore=="1":
print()
elif addmore=="2":
return
else:
print()
print("Invalid option entered")
while True:
print()
ad=str(input("Enter option to make admin or 0 to exit: ")).strip()
if ad in options:
if ad=="0":
return
ch=int(ad)
while True:
print()
print("Please confirm if you want to make "+people[ch-1][2]
+" an admin?")
print("Y: Yes")
print("N: No")
print()
sure=str(input("Enter your choice: ")).strip().lower()
print()
if sure=='y':
acursor.execute("update users set admin=1
where ucode="+str(people[ch-1][0]))
adb.commit()
print(str(people[ch-1][2]),"is now an admin")
input("Press enter to continue...")
return
elif sure=='n':
print()
print("Ignoring the admin change")
input("Press enter to continue...")
return
else:
print()
print("Invalid option entered")
print()
else:
print("Invalid Input")
print()
while True:
print()
ad=str(input("Enter option to remove admin or 0 to exit: ")).strip()
if ad in options:
if ad=="0":
return
ch=int(ad)
while True:
print()
print("Please confirm if you want to remove "+people[ch-1][2]
+" as an admin?")
print("Y: Yes")
print("N: No")
print()
sure=str(input("Enter your choice: ")).strip().lower()
print()
if sure=='y':
acursor.execute("update users set admin=0 where ucode="+
str(people[ch-1][0]))
adb.commit()
print(str(people[ch-1][2]), "is now no longer an admin")
input("Press enter to continue...")
return
elif sure=='n':
print()
print("Ignoring the admin change")
input("Press enter to continue...")
return
else:
print()
print("Invalid option entered")
print()
else:
print("Invalid Input")
print()
while True:
print()
ad=str(input("Select user to view result: ")).strip()
if ad in options:
if ad=="0":
return
ch=int(ad)
result(people[ch-1][0],people[ch-1][2])
x=1
print()
print("List of users:")
for r in people:
print(x,":","username:",r[1],"-->",r[2])
x+=1
print()
print("0 : Back to admin menu")
else:
print("Invalid Input")
print()
print("0 : Exit")
print()
if scode=="0":
print()
return
elif scode in subject_options:
acursor.execute("select name, sum(score), sum(max), count(date)
from users, results
where scode="+scode+"
and users.ucode=results.ucode
group by name order by name")
if acursor.rowcount==0:
print("No one has attempted any quiz in this subject")
else:
16
people=acursor.fetchall()
print(75*"-")
print("Result Summary for: ",subject_records[int(scode)])
print(75*"-")
print("Name".ljust(53)[:53],"No. of Quiz Score")
print(75*"-")
sumscore=0
summax=0
squiz=0
for r in people:
print(r[0].ljust(59)[:59],str(r[3]).ljust(6)[:6],
str(round(r[1]/r[2]*100,2)).rjust(6),"%")
sumscore+=r[1]
summax+=r[2]
squiz+=r[3]
print(75*"-")
print("Overall Summary".ljust(59)[:59],str(squiz).ljust(6)
[:6], str(round(sumscore/summax*100,2)).rjust(6),"%")
print(75*"-")
print()
input("Press enter to continue...")
else:
print("Invalid Option Entered")
def split(word):
return [char for char in word]
print("0 : Exit")
print()
if scode=="0":
print()
return
elif scode in subject_options:
acursor.execute("select name, sum(score), sum(max), count(date)
from users, results
where scode="+scode+" and
users.ucode=results.ucode
group by name order by name")
17
if acursor.rowcount==0:
print("No one has attempted any quiz in this subject")
else:
people=acursor.fetchall()
glen=len(people)*3+3
ustr=""
for r in range(len(people)):
ustr=ustr+str(r+1).rjust(3)[:3]
gstr=[]
gstr.append(split(" | "+glen*" "))
gstr.append(split("100% | "+glen*" "))
gstr.append(split(" | "+glen*" "))
gstr.append(split(" 80% | "+glen*" "))
gstr.append(split(" | "+glen*" "))
gstr.append(split(" 60% | "+glen*" "))
gstr.append(split(" | "+glen*" "))
gstr.append(split(" 40% | "+glen*" "))
gstr.append(split(" | "+glen*" "))
gstr.append(split(" 20% | "+glen*" "))
gstr.append(split(" |"+glen*"_"))
gstr.append(split(" 0% "+ustr))
i=1
for r in people:
s=int(round(r[1]/r[2]*100,-1))
x=10
j=10
while x<=s:
gstr[j][5+(i*3)]="█"
j-=1
x+=10
i+=1
print(75*"-")
print("Result Summary for: ",subject_records[int(scode)])
print(75*"-")
print(" # Name".ljust(53)[:53],"No. of Quiz Score")
print(75*"-")
sumscore=0
summax=0
squiz=0
i=1
for r in people:
print(str(i).rjust(2)[:2],r[0].ljust(56)[:56],
str(r[3]).ljust(6)[:6],
str(round(r[1]/r[2]*100,2)).rjust(6),"%")
sumscore+=r[1]
summax+=r[2]
18
squiz+=r[3]
i+=1
print(75*"-")
print("Overall Summary".ljust(59)[:59],str(squiz).ljust(6)[:6],
str(round(sumscore/summax*100,2)).rjust(6),"%")
print(75*"-")
print()
input("Press enter to continue...")
else:
print("Invalid Option Entered")
if new in range(1,21):
acursor.execute("update config set noofques="+str(new))
adb.commit()
print("Number of questions updated.")
input("Press enter to continue...")
print()
return
else:
print("Invalid value entered")
#admin menu to add question, subjects, set no of questions in the quiz and
manage admin rights
def adminmenu(User_code):
while True:
print(75*"-")
print("ADMIN MENU")
print()
print("1: Add new subject")
print("2: Add new question")
print("3: Make admin")
print("4: Remove admin")
print("5: Set number of questions")
print("6: Check user result")
print("7: Check subject result")
print("8: Check subject graph")
print("0: Exit")
admenuopt=str(input("Enter your choice:")).strip()
print()
if admenuopt=="1":
addsub()
elif admenuopt=="2":
addq()
19
elif admenuopt=="3":
makead(User_code)
elif admenuopt=="4":
removead(User_code)
elif admenuopt=="5":
qno()
elif admenuopt=="6":
checkuserresult(User_code)
elif admenuopt=="7":
checksubjectresult()
elif admenuopt=="8":
checksubjectgraph()
elif admenuopt=="0":
return
else:
print("Invalid Option Entered")
for x in subject_records:
print(x,": ",subject_records[x])
print("0 : Exit")
print()
if scode=="0":
print()
return False
elif scode in subject_options:
print("You have selected: ",subject_records[int(scode)])
print()
print()
quiz(scode,User_code,User_name)
else:
print("Invalid Option Entered")
if qcursor.rowcount==0:
20
print("Question bank for this subject is empty")
return
elif qcursor.rowcount<noofques:
noofques=qcursor.rowcount
quelist=qcursor.fetchall()
finalques=random.sample(quelist,noofques)
global marks
marks=0
a=1
response=''
for x in finalques:
print("Q"+str(a)+": "+x[2])
print(" 1: ",x[3])
print(" 2: ",x[4])
print(" 3: ",x[5])
print(" 4: ",x[6])
if response==str(x[7]):
print("Your answer is correct")
marks+=1
else:
print("Sorry, your answer is incorrect.","Correct option was:",x[7])
a+=1
response=''
print()
print(75*"-")
print()
print("Your Quiz Score:")
if marks==noofques:
print("Congratulations! You got a perfect score!", marks,"out of",
noofques)
elif marks==0:
print("Sorry... you did not get any questions right.")
elif marks>=noofques*0.4:
print("Congratulations! You got", marks,"out of", noofques)
else:
print("You only got", marks,"out of", noofques)
now = datetime.now()
date_time = now.strftime("%Y%m%d%H%M%S")
print(75*"-")
if len(recs)==0:
print(str(User_name)+" has not attempted any quizzes.")
else:
sub=""
print("Following are the scores of: "+User_name)
oscore=0
omax=0
oquiz=0
for r in recs:
subject=r[0]
if subject!=sub:
if sub!='':
print("Summary of",sub,": Quizzes attempted:",squiz,
“Subject result:",round(sumscore/summax*100,2),"%")
print()
print("Subject: "+subject)
print()
sumscore=0
summax=0
squiz=0
sub=subject
score=r[1]
maximum=r[2]
dt=r[3]
sumscore+=score
summax+=maximum
squiz+=1
oscore+=score
omax+=maximum
oquiz+=1
print("Result on",dt.strftime("%c"),":",score,"out of",
maximum,":",round(score/maximum*100,2),"%")
22
print("Summary of",subject,": Quizzes attempted:",squiz,
"Subject result:",round(sumscore/summax*100,2),"%")
print()
print("Overall Summary: Quizzes attempted:",oquiz,
"Overall result:",round(oscore/omax*100,2),"%")
print()
input("Press enter to continue...")
rcursor.close()
rdb.close()
#main program
mydb=mysql.connector.connect(host="localhost",user="root",passwd="rsma9112!",
database="quiz_project")
mycursor=mydb.cursor()
mycursor.execute("select * from subjects")
recs=mycursor.fetchall()
mycursor.close()
mydb.close()
subject_records= {}
for r in recs:
subject_records[r[0]]=r[1]
subject_options.append(str(r[0]))
subject_options.append(str(0))
adb=mysql.connector.connect(host="localhost",user="root",passwd="rsma9112!",
database="quiz_project")
acursor=adb.cursor(buffered=True)
while True:
print()
print()
print(" ______ ____ ___ ______")
print("\ / | | / / \ |\ /| | ")
print(" \ / | | / / \ | \ / | | ")
print(" \ /\ / |------ | | | | | \/ | |------")
print(" \ / \ / | | \ \ / | | | ")
print(" \/ \/ |______ |______ \_____ \___/ | | |______")
print()
loginmenu()
23
Databases used in the
program
CREATE DATABASE `quiz_project` ;
OUTPUT
Welcome menu
Register
25
Login
26
Admin Menu
27
Take a quiz
28
Viewing Result
Going back
29
Add New Subject
30
Add New Question
31
Make user an admin
32
Remove user from admin
…..Otherwise…
33
Changing Password
34
Set number of questions
35
36
37
Check subject result
38
Check subject graph
39
40
41
Exiting the program
42
Quiz Data
qco sco Question option_1 option_2 option_3 option_4 answ
de de er
1 1 What is the national sport Cricket Hockey Kabaddi Football 2
of India?
2 1 Which Indian captain won Sunil Ravi Kapil Dev Mohinder 3
the 1983 Cricket World Gavaskar Shastri Amarnath
Cup?
3 1 When were first 1930 1953 1941 1921 1
commonwealth games
held?
4 1 How many players are 6 10 11 9 3
there in each side of
Hockey team?
5 1 The name Kunjarani Devi is Weight Target Athletics Swimming 1
associated with…? Lifting Shooting
6 1 Ricky Ponting is also known The Pont Ponter Punter 4
as …. rickster
7 1 How long are professional 45 sec 1 min 2 min 30 sec 1
Golf Tour players allotted
per shot?
8 1 In which city the 2028 Amsterda Tokyo Paris Los Angeles 4
Summer Olympic Games m
will be organized?
9 1 How many players are 10 6 5 8 2
there in a team of
Volleyball?
10 1 Deepa Karmakar is Badminton Shooting Boxing Gymnastics 4
associated with which
sports?
11 1 Commonwealth Games are 5 4 6 3 2
held after every _____
years
12 1 How many Grand 1 2 3 4 4
Slam tennis tournaments
are held every year?
13 1 Who won the first T20 Sri Lanka USA India Canada 3
World Cup?
14 1 Which country has won the Australia England South Africa USA 1
world cup three times in a
row?
15 1 Who is known as the God of Virender Sachin M.S. Dhoni Virat Kohli 2
Cricket ? Sehwag Tendulka
r
16 1 The famous football player Brazil Chile Argentina Italy 3
Maradona belongs to which
country?
43
17 1 Which country has won the Russia China Germany Brazil 4
World Cup Football the
maximum number of
times?
18 1 Which of the following Australian Wimbled US Open French 2
international tennis Open on Open
tournaments is held on
grass court?
19 1 How many times has India 2 4 3 1 1
won the ICC World Cup?
20 1 Who is known as the king of Roger Novak Rafael Nadal Dominic 3
clay in tennis? Federer Djokovic Thiem
21 2 Which figure has no line of Circle Sqaure Scalene Rectangle 3
symmetry? Triangle
22 2 Number of radii a circle can 1 6 7 Infinite 4
have are
23 2 Two successive numbers 3 and 5 2 and 11 5 and 13 7 and 17 1
which are prime
24 2 Solve for m: 2m+18-(14- 10 11 20 30 2
9)=35
25 2 Who invented the number S. Shakunta S.N. Bose Aryabhatta 4
0? Ramanujan la Devi
26 2 What is three - fifth of 50? 30 10 45 28 1
27 2 How many egdes does a 10 23 12 7 3
cube have?
28 2 Who is known as the Father Isaac Fibonacci Albert Archimedes 4
of Mathematics? Newton Einstein
29 2 How many seconds are 2800 3600 1000 2500 2
their in an hour?
30 2 What is the name of this Arithemeti Geometri Fibonacci Harmonic 3
sequence?…...0,1,1,2,3,5, c c Series Progression
8,13…. Progressio Progressi
n on
31 2 Who is known to be the Shakuntala Aryabhat Pythagoras Albert 1
Human Calculator? Devi ta Einstein
32 2 What is a figure with 6 sides Pentagon Nonagon Decagon Hexagon 4
called?
33 2 Three angles of a 89 45 56 98 1
quadrilateral are 47°,
128° and 96°. Find the
fourth angle.
34 2 What is the area of a right 250 500 450 300 2
angle traingle with base 40
cm and height 25 cm?
35 2 Between which of the 4 and 5 9 and 10 6 and 7 7 and 8 3
following numbers does the
cube root of 37 lie?
36 2 How many composite 7 5 4 6 1
numbers are there between
20 and 29?
44
37 2 What is the least common 175 150 100 200 4
multiple of 100 and 200?
38 2 Which of the following is 8 6 12 18 1
not a factor of 180?
39 2 What is the square root of 545 453 788 321 2
205209?
40 2 The product of an irrational Integer Rational Irrational Natural 3
and a rational number is Number Number Number
41 3 The tissue responsible for Stomata Xylem Root Hair Phloem 4
the transportation of food
in plants is
42 3 Which of the following is a Fungus Algae Cuscutta Lichens 3
parasite?
43 3 Which organisms prepare Autotrophs Hetrotro Parasite Saprophyte 1
food for themselves from phs s
raw materials?
44 3 A cell is enclosed by a thin Chromatin Cell Cytoplasm Guard Cells 2
outer boundary called Membra
ne
45 3 Which of the following Cobalt Ebonite Steel Iron 2
cannot be used to make a
magnet?
46 3 The nerves in our body Electric Radio Electromagn None 1
transmit messages as Impulse Waves etic Waves
47 3 Wool is obtained from Pig Horse Sheep Elephant 3
48 3 What is the sure test of Attraction Repulsion Both None 2
magnetism?
49 3 The process of using a Spinning Weaving Ginning Knitting 4
single yarn to make a piece
of fibre is known as
50 3 Jute fibre is obtained from Stem Root Leaves Flowers 1
which part of the jute plant
51 3 Which of the following is an Melting of Formatio Burning of Melting of 3
irreversible change? ice n of ice coal wax
52 3 Moving air is called Cyclone Wind Storm Tsunami 2
53 3 Electric wires and parts of Silver Copper Gold Plastic 4
electrical appliances are
covered with
54 3 Which of the following is a Goat Cow Lion Deer 3
carnivore?
55 3 What is germination of Sprouts Sapling Vegetation None 1
seed known as?
56 3 Which of the following is an Silver Rubber Iron Copper 2
insulator?
57 3 When air is passed through Water Oxygen Nitrogen Carbon 4
lime water it turns milky. Vapour dioxide
This is due to
58 3 Breathing is a part of a Respiration Digestion Circulation Photosynth 1
process called esis
45
59 3 An electric cell produces Current Energy Chemicals Light 3
electricity from the
_______ stored inside it
60 3 The surrounding where an Acclimitiza Habitat Adaptation Habit 2
organism lives is called a tion
61 4 Who was the last viceroy of Lord Lord Lord Irwin Lord 4
India? Canning Wellesley Mountbatt
en
62 4 In which year was the first 1651 1630 1655 1647 1
English Factory setup?
63 4 The third battle of Panipat 1792 1756 1763 1770 3
was fougt in which year?
64 4 Which of the following was Bengal Kalikata Madras Bombay 2
not a presidency ?
65 4 Who wrote an influential Mirabeau Jean Paul Olympe De Abbe 4
pamphlet What is the Third Marat Gouges Seiyes
Estate""?""
66 4 Who was the leader of Stalin Lenin Karl Marx Louis Blanc 1
Bolshevik Party?
67 4 When did world war one 1911 1914 1910 1917 2
begin?
68 4 Which of the following Italy Japan India France 4
countries were part of the
allied forces in World War
II?
69 4 Which of the following The spirit A tale of Two The Social 3
books was written by John of law two cities Treatises of Conract
Locke? Gov
70 4 When did second world war Jan-47 May-45 Jun-45 Oct-46 2
end?
71 4 Who wrote Mien Kamph? Adolf Hitler Charles Herbert Goebbels 1
Darwin Spencer
72 4 Who wrote the book Hind Jawarlal B.R. Mahatma Rabindrana 3
Swaraj""?"" Nehru Ambedka Gandhi th Tagore
r
73 4 Â Where did the brutal Lucknow Lahore Meerut Amritsar 4
‘Jallianwala
Massacre’ take place?
74 4 Which incident lead to the German Blast at Russian German 1
start of the World War II? invasion of Hiroshim invasion of invasion of
Poland a- Germany Switzerland
Nagasaki
75 4 Who was the successor of Trotskii Kerinski Stalin Karl Marx 3
Lenin?
76 4 Who set up the Oudh Kisan Alluri Jawahar Jawaharlal Mahatma 2
Sabha? Sitaram Lai Nehru Nehru and Gandhi
Raju and Baba Shaukat Ali
Ramchan
dra
77 4 Who was the founder of Huyunh Liang Phan Boi Ngyuyen 1
the Hoa Hao Movement? Phu So Oichao Chau Dinh Chieu
46
78 4 Who were the 'Trung Writers Actors Women None 3
Sisters'? rebels in
Vietnam
79 4 Who founded the  Alluri C.R. Das  M.R. Dr B.R. 4
‘Depressed Classes Sitaram Jayakar Ambedkar
Association’ in 1930? Raju
80 4 When did India gain 1937 1947 1950 1945 2
independence?
81 6 Is there atmosphere in Yes No - - 2
space?
82 5 How many continents are 5 6 9 7 4
there in the world?
83 7 Which of the following is Windows Mac Google Linux 3
not an operating system?
SQL TABLES
47
48
BIBLIOGRAPHY
49
Sumita Arora – Computer Science with Python – Class XII
Wikipedia
w3schools.com
tutorialspoint.com
YouTube
50