473,224 Members | 1,658 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,224 software developers and data experts.

project - trivia game

For my final project, I'm trying to do a GUI based game similar to are
you smarter then a 5th grader. I've been working on it and am stuck
with some code someone helped me with to randomize the A,B,C,D letters
that the correct answer is assigned too. The code that does this is
highlighted in bold and the code that assigns it to a variable is also
in bold so I can test it in the console window. Problem is, it's always
stuck at letter A and doesn't always give the correct answer. The
correct answer is always position 1 in my make math question list.
Could someone please help?


BTW, to whoever asked me why I don't use functions b4, I'm using them
now that I've learned how to... :P ;)

from graphics import *
from random import *

def drawMainMenu(win):
#define and draw the buttons
mainMenuList = []
mainMenuList.append (CreateRect(4,6,7,8,"grey",win))
mainMenuList.append (CreateRect(3.5,6.5,5,6,"grey",win))
mainMenuList.append (CreateRect(3.5,6.5,3,4,"grey",win))
mainMenuList.append (CreateRect(3.1,7,1,2,"grey",win))
mainMenuList.append (CreateRect(8,10,0,1,"grey",win))

#define and draw the main menu
mainMenuList.append (CreateText(5,9.5,"MAIN MENU","times roman", 30,
"normal", "red",win))
mainMenuList.append (CreateText(2,8.5,"Please pick a subject from
below: ","times roman", 14, "normal", "purple",win))
mainMenuList.append (CreateText(5,7.5,"MATH","times roman", 28,
"italic", "blue",win))
mainMenuList.append (CreateText(5,5.5,"SCIENCE","times roman", 28,
"italic", "yellow",win))
mainMenuList.append (CreateText(5,3.5,"HISTORY","times roman", 28,
"italic", "pink",win))
mainMenuList.append (CreateText(5,1.5,"GEOGRAPHY","times roman", 28,
"italic", "green",win))
mainMenuList.append (CreateText(9,.5,"Quit","times roman", 20,
"italic", "black",win))


def UndrawMenu (menulist):
for i in range(len(menulist)):
def CreateText(x,y,myString,myFace,mySize, myStyle, myColor,win):
myText = Text(Point(x,y), myString)
return myText

def CreateRect(x1,x2,y1,y2,myFill,win):
myRect = Rectangle(Point(x1,y1,), Point(x2,y2))
return myRect

def isValidClick(x1,x2, y1, y2, p1, win):
if p1.getX()>=x1 and p1.getY()>=y1 and p1.getX()<=x2 and p1.getY()<=y2:
return True
return False

def drawQuestion (subject, question, answers, win):
menuList = []

#define and draw the entry boxes
entchoice = Entry(Point(6.4,6.5), 1)
entchoice.setTextColor ("blue")

menuList.append(CreateText(5,9.5,question,"times roman", 18,
"normal", "red",win))
menuList.append(CreateText(2,8.5,"A. " + answers[0],"times roman",
16, "normal", "purple",win))
menuList.append(CreateText(7.5,8.5,"B. " + answers[1],"times roman",
16, "normal", "purple",win))
menuList.append(CreateText(2,7.5,"C. " + answers[2],"times roman",
16, "normal", "purple",win))
menuList.append(CreateText(7.5,7.5,"D. " + answers[3],"times roman",
16, "normal", "purple",win))
menuList.append(CreateText(4.7,6.5,"Please enter your
choice:","times roman", 16, "normal", "purple",win))

#draw answer box and text
answerButton = Rectangle(Point(7,5.5), Point(3,4))
answerButton = Text(Point(5,4.8),"Answer")

def main():

#Declare and initialize variables

#make math question list
mathlist = []
question = ["An equilateral triangle has how many sides?", "3", "4"
, "1", "5"]
question = ["How many inches are in a foot?", "12", "6", "3", "9"]
question = ["One Kilogram equals how many grams?", "1000", "230",
"450", "100"]
question = ["Which means nine hundred sixty three thousandths?",
".963", ".0963", ".0.0963", "9.63"]
question = ["A fathom is a unit of measurement for which of the
following?", "depth", "space", "time", "distance"]
question = ["What is 111, plus 112, plus 113?", "336", "332", "331",

#show the rules of the game window
win = GraphWin("RULES OF THE GAME",600,600)

txtrules1 = CreateText(5,9.5,"The rules of the game are as
follows:","times roman", 16, "normal", "red",win)
txtrules2 = CreateText(5,8.5,"The game will be made up of 10
questions, 2 from each grade 1-5.","times roman", 12, "normal", "black",win)
txtrules3 = CreateText(5,7.5,"You will be able to pick 2 subjects
you want to answer for each grade.","times roman", 12, "normal",
txtrules4 = CreateText(5,6.5,"The subjects you can pick from are
Math, Science, History and Geography.","times roman", 12, "normal",
txtrules5 = CreateText(5,5.5,"No more then 3 questions can be
answered from each subject.","times roman", 12, "normal", "black",win)
txtrules6 = CreateText(5,2.5,"HAVE FUN AND GOOD LUCK!","times
roman", 26, "normal", "yellow",win)
#define window and set coords
win =GraphWin("Are You Smarter Then a Fifth Grader???",800,800)
mainMenuList = drawMainMenu(win)

p1 = win.getMouse()
if (isValidClick(4,6,7,8,p1,win)==True):
currentList = mathlist
subject = "Math"

elif (isValidClick(3.5,6.5,5,6,p1,win)==True):

elif (isValidClick(3.5,6.5,3,4,p1,win)==True):

elif (isValidClick(3.1,7,1,2,p1,win)==True):


* #Picks random question
qNum = randrange(0, len(currentList))
qList = currentList[qNum]

aList = []
tmpList = qList[1:5]

#Randomizes answers
while(len(tmpList) 0):
rNum = randrange(0, len(tmpList))

currentScreen = drawQuestion(subject, qList[0], aList, win)

p1 = win.getMouse()
print "hello"

pResult = (currentScreen[0].getText())
print pResult

cResult = (currentScreen[2].getText())
print cResult*

#compare player's answer to correct answer
#if correct/incorrect do a print statement
#add/take away from score

Dec 5 '07 #1
0 1659

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: yongbl | last post by:
Hi, I need to do a client-server project that involves TCP/IP and XML. I want to make it a meaningful project. My friends suggested doing a project on Web Service. What kind of web services...
by: alcueca | last post by:
Hi, I've been programming with python and pygame for a year now, I started a RPG game, did some small toy apps (like exploring mandelbrot set) and an entire End-of-Career project about...
by: ashwin2mittal | last post by:
Dear friends, I am looking for help regarding major project ideas in C and C++. This project is a part of the my computer engg curriculum. Kindly help me in finding out the ideas ASAP. ...
by: Tim Simmons | last post by:
I am stumped. I encoded the action = of my form using GET and I can't seem to get the property/value stuff from it using a JavaScript script I got from the web. I want to create a trivia game...
by: Vladimír Kolesnik | last post by:
Hi, there we need help concerning setting project under source control. We want to have a project on the server, and developers in the local network working on this project. We decided to use...
by: venkatmail20034u | last post by:
hai to everybody, i desired to do a project in c? if u have idea about what types of problem solved by the c language? and also specify if u have any project title with description please specify...
by: robinsand | last post by:
My apologies to those of you who are more advanced Visual C++ .NET programmers, but I am working on a project for an MBA course that is condensed into an eight-week schedule, and I need help...
by: Karlsen | last post by:
Hi everyone. I've been browsing your forums for a week or too, looking for information about RPG games. I'm very new to the whole C++ thing, but feel like im getting a hang of it. As a part of...
by: alesitaam | last post by:
Help!!!! Im new using python, currently writing a program which tests one game, IQ test. When the module is run, the program should ask user to choose the game to start. Also, I'm using Try...Except...
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
by: VivesProcSPL | last post by:
Obviously, one of the original purposes of SQL is to make data query processing easy. The language uses many English-like terms and syntax in an effort to make it easy to learn, particularly for...
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
by: jimatqsi | last post by:
The boss wants the word "CONFIDENTIAL" overlaying certain reports. He wants it large, slanted across the page, on every page, very light gray, outlined letters, not block letters. I thought Word Art...
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.