473,804 Members | 4,014 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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?

thanks

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(wi n):
#define and draw the buttons
mainMenuList = []
mainMenuList.ap pend (CreateRect(4,6 ,7,8,"grey",win ))
mainMenuList.ap pend (CreateRect(3.5 ,6.5,5,6,"grey" ,win))
mainMenuList.ap pend (CreateRect(3.5 ,6.5,3,4,"grey" ,win))
mainMenuList.ap pend (CreateRect(3.1 ,7,1,2,"grey",w in))
mainMenuList.ap pend (CreateRect(8,1 0,0,1,"grey",wi n))

#define and draw the main menu
mainMenuList.ap pend (CreateText(5,9 .5,"MAIN MENU","times roman", 30,
"normal", "red",win))
mainMenuList.ap pend (CreateText(2,8 .5,"Please pick a subject from
below: ","times roman", 14, "normal", "purple",wi n))
mainMenuList.ap pend (CreateText(5,7 .5,"MATH","time s roman", 28,
"italic", "blue",win) )
mainMenuList.ap pend (CreateText(5,5 .5,"SCIENCE","t imes roman", 28,
"italic", "yellow",wi n))
mainMenuList.ap pend (CreateText(5,3 .5,"HISTORY","t imes roman", 28,
"italic", "pink",win) )
mainMenuList.ap pend (CreateText(5,1 .5,"GEOGRAPHY", "times roman", 28,
"italic", "green",win ))
mainMenuList.ap pend (CreateText(9,. 5,"Quit","tim es roman", 20,
"italic", "black",win ))

return(mainMenu List)

def UndrawMenu (menulist):
for i in range(len(menul ist)):
menulist[i].undraw()
def CreateText(x,y, myString,myFace ,mySize, myStyle, myColor,win):
myText = Text(Point(x,y) , myString)
myText.setFace( myFace)
myText.setSize( mySize)
myText.setStyle (myStyle)
myText.setTextC olor(myColor)
myText.draw(win )
return myText

def CreateRect(x1,x 2,y1,y2,myFill, win):
myRect = Rectangle(Point (x1,y1,), Point(x2,y2))
myRect.setFill( myFill)
myRect.draw(win )
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
else:
return False

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

#define and draw the entry boxes
entchoice = Entry(Point(6.4 ,6.5), 1)
entchoice.setTe xt("A")
entchoice.setTe xtColor ("blue")
entchoice.draw( win)

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

#draw answer box and text
answerButton = Rectangle(Point (7,5.5), Point(3,4))
answerButton.se tFill("grey")
answerButton.dr aw(win)
answerButton = Text(Point(5,4. 8),"Answer")
answerButton.se tTextColor("bla ck")
answerButton.se tSize(22)
answerButton.dr aw(win)
menuList.append (answerButton)

return(menuList )
def main():

#Declare and initialize variables

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

#show the rules of the game window
win = GraphWin("RULES OF THE GAME",600,600)
win.setBackgrou nd("orange")
win.setCoords(0 .0,0.0,10.0,10. 0)

txtrules1 = CreateText(5,9. 5,"The rules of the game are as
follows:","time s 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",
"black",win )
txtrules4 = CreateText(5,6. 5,"The subjects you can pick from are
Math, Science, History and Geography.","ti mes roman", 12, "normal",
"black",win )
txtrules5 = CreateText(5,5. 5,"No more then 3 questions can be
answered from each subject.","time s roman", 12, "normal", "black",win )
txtrules6 = CreateText(5,2. 5,"HAVE FUN AND GOOD LUCK!","times
roman", 26, "normal", "yellow",wi n)
#define window and set coords
win =GraphWin("Are You Smarter Then a Fifth Grader???",800, 800)
win.setBackgrou nd("orange")
win.setCoords(0 .0,0.0,10.0,10. 0)
mainMenuList = drawMainMenu(wi n)

#getMouse
p1 = win.getMouse()
while(isValidCl ick(8,10,0,1,p1 ,win)==False):
if (isValidClick(4 ,6,7,8,p1,win)= =True):
currentList = mathlist
subject = "Math"

elif (isValidClick(3 .5,6.5,5,6,p1,w in)==True):
UndrawMenu(main MenuList)

elif (isValidClick(3 .5,6.5,3,4,p1,w in)==True):
UndrawMenu(main MenuList)

elif (isValidClick(3 .1,7,1,2,p1,win )==True):
UndrawMenu(main MenuList)

UndrawMenu(main MenuList)

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

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

#Randomizes answers
while(len(tmpLi st) 0):
rNum = randrange(0, len(tmpList))
aList.append(tm pList[rNum])
tmpList.pop(rNu m)*

currentScreen = drawQuestion(su bject, qList[0], aList, win)
currentList.pop (qNum)

#getMouse
p1 = win.getMouse()
while(isValidCl ick(7,3,5.5,4,p 1,win)==True):
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

UndrawMenu(curr entScreen)
#Quit
win.close()
Dec 5 '07 #1
0 1683

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

Similar topics

3
1844
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 should I do? Any suggestions? Thanks in advance, Yong
1
1306
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 Evolutionary Computing and Natural Algorithms (5000 lines more or less) with this language. I'd like to use this knowledge in some funny way, I'd like to code a good game, maybe some RPG or platform-type, but I don't want to do it alone, neither to start...
7
8058
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. Thanks, Ashwin
2
2223
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 where the user gets 1 question at a time and it keeps scoring until the end and gives a summary and I want to do it only in JavaScript (no ASP, PHP, JSP, etc). I tried submitting the quiz page to itself using a query string to keep track of...
1
1605
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 strategy officialy called "Isolated Development". We studied help in Visual Studio .NET called "Web Projects and Source Control Integration in Visual Studio ..NET". First we created solution on machine: A (server), then added a web project to this...
20
1673
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 to me thanks in advance
4
2217
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 getting a program up and running with proper files and documentation to be handed in for a grade (on Microsoft Visual Studio .NET 2003). I am being graded on how well I incorporate advanced C++ features such as inheritance, polymorphic programming,...
5
4114
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 my examn project this year, i've decided to program a simple 2D-Rpg game (if possible!). Let me just tell your about my basic idea, then ill get to the questions. The game: I would like to make a very simple 2D inviroment, where the player will...
5
4586
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 statements, and os file operator. My code needs some adjustments, most of all at the end. Please give some tips!!! import os while True: print"Welcome to trivia game!" print "0-Choose a game to play:" print "1- IQ Test.trv"
0
9710
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9589
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
10329
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7626
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6858
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5663
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4304
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3830
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3000
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.