•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 397,592 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,873 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser:
Views: 2200 | Replies: 8
![]() |
Please help me, I want to make a quiz in python (And a game, if I get the time), can someone help me?
I saw the topic projects for beginners, but it was a .dat file (which I opened using notepad 2), I don't know how to use a dat file with python, I am used to .py files.
And .html files.
Please help,
Panarchy
I saw the topic projects for beginners, but it was a .dat file (which I opened using notepad 2), I don't know how to use a dat file with python, I am used to .py files.
And .html files.
Please help,
Panarchy
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,408
Reputation:
Rep Power: 9
Solved Threads: 173
Welcome to DaniWeb and the interesting world of Python coding!
The Quiz.dat file is just a text file containing 6 lines per question. The first line is the correct answer code for the four possible answers (A, B, C, D), followed by the question and the four possible answers. For example ...
To work with it in Python, it is easiest to form a tuple/array of each question in a set order and put them in a list. I picked the order (question, answer1, answer2, answer3, answer4, answer_code). The reason I used a list of tuples is that you can shuffle them easily. You read the data file into your program as a list of text lines and then convert these to a list of the question tuples ...
Here is a short Python program to handle the formation of the list of tuples ...
Now its up to you to display the question, followed by the four possible answers titled A, B, C, D and ask the player to give the title letter of the correct answer. After the user gives the input, then you compare the letter with the letter of the correct answer.
The Quiz.dat file is just a text file containing 6 lines per question. The first line is the correct answer code for the four possible answers (A, B, C, D), followed by the question and the four possible answers. For example ...
A Which sport uses the term LOVE ? Tennis Golf Football Swimming B What is the German word for WATER ? Wodar Wasser Werkip Waski C What has eight bits ? Word ASCII Byte RAM ... ...
python Syntax (Toggle Plain Text)
[('Which sport uses the term LOVE ?', 'Tennis', 'Golf', 'Football', 'Swimming', 'A'), ('What is the German word for WATER ?', 'Wodar', 'Wasser', 'Werkip', 'Waski', 'B'), ('What has eight bits ?', 'Word', 'ASCII', 'Byte', 'RAM', 'C'), ...]
python Syntax (Toggle Plain Text)
# read the mutliple choice quiz data file # reorganize into a list of tuples, each tuple has this order # (question, answer1, answer2, answer3, answer4, answer_code) # read the appended text file as a list of lines fin = open("Quiz.dat", "r") lineList = fin.readlines() fin.close() quiz_list = [] for k, line in enumerate(lineList): tuple_complete = False line1 = line.strip() # build a tuple for each question if k % 6 == 0: answer_code = line1 if answer_code == 'end': break if k % 6 == 1: question = line1 if k % 6 == 2: answer1 = line1 if k % 6 == 3: answer2 = line1 if k % 6 == 4: answer3 = line1 if k % 6 == 5: answer4 = line1 tuple_complete = True if tuple_complete: tuple1 = (question, answer1, answer2, answer3, answer4, answer_code) print tuple1 # test quiz_list.append(tuple1) print "-"*70 #print quiz_list # for testing print "-"*70 # shuffle the list and display the first 10 question tuples import random random.shuffle(quiz_list) for k, quest in enumerate(quiz_list): if k < 10: print quest
Last edited by vegaseat : May 13th, 2007 at 2:44 pm.
May 'the Google' be with you!
•
•
Join Date: Oct 2004
Location: Mojave Desert
Posts: 2,408
Reputation:
Rep Power: 9
Solved Threads: 173
•
•
•
•
I am a bit of a noob. I have only just started learning python. Please help I don't understand this.
If you are that unfamiliar with Python, I would recommend to work yourself through a simple tutorial first, and then a few simple projects. The Quiz program is more of medium difficulty. You have to know about lists, tuples, random functions, file handling and so on.
Here is a good recommendation of tutorial sources posted a few days ago:
http://www.daniweb.com/techtalkforums/post363044-4.html
What dont you understand?
Editors note: This thread refers to http://www.daniweb.com/techtalkforum...161212-13.html
Last edited by vegaseat : May 14th, 2007 at 4:46 pm. Reason: note
May 'the Google' be with you!
•
•
Join Date: Feb 2007
Posts: 55
Reputation:
Rep Power: 2
Solved Threads: 1
Hi,
I also wanted to use other languages for a game etc that I wanted to do, so before I took on any language for what was needed I looked at how easy it would be for me to code my game in...C, C++, C#, Ruby, Perl, Java and while looking at these I accidently found Python...and thank goodness that I did! Some of these other codes can take 6 or 7 times longer to code with than Python and are 6 or 7 times more complicated to deal with! I've read where some math professors were involved in some complicated mathematical equations and dreaded using an equally complicated language like C to code it in
...I've also read where people can take 7 or 8 months to code a project in say C where if they did the same thing in Python it would take only 2 weeks...so to say I'll just learn C etc like one is going to have an enjoyable steak lunch does not equate at all!
Believe me when I say that not every language is as easy to use as our beloved Python.
fredzik.
I also wanted to use other languages for a game etc that I wanted to do, so before I took on any language for what was needed I looked at how easy it would be for me to code my game in...C, C++, C#, Ruby, Perl, Java and while looking at these I accidently found Python...and thank goodness that I did! Some of these other codes can take 6 or 7 times longer to code with than Python and are 6 or 7 times more complicated to deal with! I've read where some math professors were involved in some complicated mathematical equations and dreaded using an equally complicated language like C to code it in
...I've also read where people can take 7 or 8 months to code a project in say C where if they did the same thing in Python it would take only 2 weeks...so to say I'll just learn C etc like one is going to have an enjoyable steak lunch does not equate at all!Believe me when I say that not every language is as easy to use as our beloved Python.
fredzik.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb Python Marketplace
•
•
•
•
accounting software selection business software console core deafblind development environment erp systems evaluation evaluations fedora game games handheld legacy linux live microsoft msn nintendo playstation programming project project management ps3 psp python recycling selection software software selection software solutions sony stocks technology evaluation video video game wii wiimote xbox xbox 360
- Modifying a project in python (Python)
- Starting a Project (C)
Other Threads in the Python Forum
- Previous Thread: begginer
- Next Thread: please help i am very desperate



Linear Mode