


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A project made from connecting python and mysql a quiz program
Typology: High school final essays
1 / 26
This page cannot be seen from the preview
Don't miss anything!



















PROBLEM ANALYSIS The program includes the following functions : 1.CREATION OF QUIZ 2.MODIFICATION OF QUIZ 3.DELETION OF QUIZ 4.USAGE (ATTEMPTING) OF QUIZ 5.CHECKING SCORES OF PARTICIPANTS Here anyone with access to a system can create quiz accessible to other user,and also attempt others quizzes. Moreover various other functions are possible.
SYSTEM REQUIREMENTS
SOURCE CODE import mysql.connector as ms mycon=ms.connect(user='root',host='local host',passwd='krishu1512',database='pyc on') mycur=mycon.cursor() #Addition of records def maketest(): Name=input("Enter name :") QRY="CREATE TABLE %s(QUESTION TEXT,CHOICE1 VARCHAR(80),CHOICE VARCHAR(80),CHOICE VARCHAR(80),CHOICE VARCHAR(80),CRCTCHOICE CHAR(1))"%(Name,) mycur.execute(QRY) mycon.commit()
SamAns=[["Vanilla","Chocolate","Cookie Dough","Strawberry"], ["Dolphin","Rabbit","Shark","Panda bear"], ["Avengers: Endgame","It: Chapter Two","Toy Story 4","Spider-Man: Far From Home"], ["Astronaut","Actor/Actress","Jedi","Scienti st"], ["February 21","May 8","May 29","January 14"], ["Stranger Things","Bridgerton","Squid Game","Narcos"], ["Big house party","Night out","Surprise party","Costume party "], ["Spiders","Heights","Flying","Blood"], ["Dancing","Singing","Drawing","Writing"],
["WhatsApp","YouTube","Instagram","Sna pchat"]] print("""You can either select the default questions / options or enter your own To enter a default value just press enter and leave the column blank """) for i in range(10): print(SamQues[i]) QUES=input("") if len(QUES)==0: QUES=SamQues[i] A=['A','B','C','D'] CHCS=[] for j in range(4): print(A[j],'. ',SamAns[i][j],sep='') print(A[j],'. ',sep='',end='') choice=input('') if len(choice)==0:
mycur.execute('SHOW TABLES') data=mycur.fetchall() found="False" while found=="False": FName=input("Enter your friend's name: ") for i in data: if i[0]==FName: found="True" break else: print("That person has not attended the test.Check for capitals or try another name") found="False" stop=input("Enter STOP to stop taking test or just press ENTER to continue") if stop=="STOP": break if stop!="STOP":
mycur.execute("SELECT * FROM %s"%FName) Score= data1=mycur.fetchall() for i in data1: for j in range(5): print(i[j]) CHOICE=input("Enter the correct option: ") if CHOICE==i[5]: Score+= print("You have got a score of",Score) QRY3="INSERT INTO %sSCORE VALUES('%s',%s)"%(FName,Name,Score ) mycur.execute(QRY3) mycon.commit() else: return def checkscore():
data=mycur.fetchall() for i in data: print(i[0],i[1]) else: return def changetest(): mycur.execute('SHOW TABLES') data=mycur.fetchall() found="False" while found=="False": Name=input("Enter your name: ") for i in data: if i[0]==Name: found="True" break else: print("You have not attended the test.Check for capitals or try another name") found="False"
stop=input("Press enter STOP just press ENTER to continue") if stop=="STOP": break if stop!="STOP": mycur.execute("SELECT * FROM %s"%Name) data1=mycur.fetchall() mycur.execute("DELETE FROM %s"%Name) for i in range (10): for j in range(5): print(data1[i][j]) change=input("Do you wish to change this question y/n?") if change=='y': print(data1[i][0]) QUES=input("") if len(QUES)==0: QUES=data1[i][0] A=['A','B','C','D'] CHCS=[]
val=(Name,data1[i][0],data1[i][1],data1[i][ ],data1[i][3],data1[i][4],data1[i][5]) QRY1='INSERT INTO %s VALUES ("%s","%s","%s","%s","%s","%s")'%val mycur.execute(QRY1) mycon.commit() else: print("Invalid choice") def deletetest(): mycur.execute('SHOW TABLES') data=mycur.fetchall() found="False" while found=="False": Name=input("Enter your name: ") for i in data: if i[0]==Name: found="True" break else:
print("You have not attended the test.Check for capitals or try another name") found="False" stop=input("Press enter STOP just press ENTER to continue") if stop=="STOP": break if stop!="STOP": mycur.execute("DROP TABLE %s"%Name) mycur.execute("DROP TABLE %sSCORE"%Name) mycon.commit() rep='y' while rep=='y': ch=int(input(""" BEST FRIEND QUIZ What do you want to do?