PDA

View Full Version : Create a simple quiz program




Azrak
Apr 2, 2013, 02:36 PM
I have a history exam and for preparation i wanted to create a quiz (not a multiple answer one). I searched on many websites for an easy way to create a quiz but none of them corresponded to what i really want.

What I want is a quiz with questions in a random order (I prefer the order to vary each time i take the quiz) and I have to answer the questions by typing my result, not by clicking on it (i don't want the quiz to be a multiple answer quiz). Right after typing my result i want the quiz to display the correct answer (whether my result is correct or false).

Can anyone of you help me create a program that could do just that? I have done some programming before so I do know how it works but I'm not good enough to create my own program by myself. If not, does anyone know of a site that lets you create your own quiz but this type of quiz explained above (I want the quiz to work this way)?

All your help will appreciated
Azrak



Hans Kamp
Apr 2, 2013, 04:39 PM
I think it helps if you write down for yourself, what this program is supposed to do.

To start with, your quiz is a collection of questions, objects. And each question has multiple answers to pick, and the correct andwer.

How are these answers stored? How do you want the quiz to appear on screen?

These are things to tuink about.

ArtOfWarfare
Apr 2, 2013, 04:50 PM
If its console based, I think the quickest and easiest way to do this would be:

Make a text file with your Questions and Answers. Have it follow a simple pattern like:

"Question? Answer.
Another question? Another answer."

with one question? Answer pair per line.

Read the lines into a container (IE, a vector in C++), then shuffle the container. A simple shuffle algorithm I've used is:

Seed a random number generator.
For the amount of items (n) in the container, generate a random number between 0 and n-i-2, where i is how many iterations already completed. Then swap the item at index n-i-1 with the item at the index randomly generated.

Now loop with:
Get the substring up to and including the question mark and print it.
Wait for the user input.
Get the substring past the question mark and print it.

Azrak
Apr 3, 2013, 03:22 AM
What do you mean by
How are these answers stored? How do you want the quiz to appear on screen?


I will create all my questions and associate an answer to each question.
I want the program to ask me those questions in a random order and prompt me to type the answer. After i type my answer i want the program to show me the correct answer whether or not my answer is correct.

Azrak
Apr 3, 2013, 04:04 AM
I know i can find a site where i can create my own quiz but none of those sites work the way i want them to. What I want, that is different from all websites that offer me to create a quiz, is the quiz to display the correct answer after answering each question. This is the important part for me and that is why im trying to create my own program.

AtariMac
Apr 3, 2013, 05:49 AM
Use Scratch. It's easy to learn and free. http://scratch.mit.edu

Have at it!

ytk
Apr 3, 2013, 12:26 PM
What language are you trying to do this in?

Here's a program that will do it in Ruby: #!/usr/bin/ruby -w

quiz_data = File.read( ARGV[0] ).split "\n"
questions = []
questions << [quiz_data.shift, quiz_data.shift] while quiz_data.size > 0
questions.shuffle!
questions.each do |q|
print q[0] + " "
STDIN.gets
puts q[1]
puts
end


Save your questions in a text file, one question per line followed by the answer on a separate line. Then invoke the program with “./quiz.rb <filename>”

ArtOfWarfare
Apr 3, 2013, 12:46 PM
What language are you trying to do this in?

Here's a program that will do it in Ruby: #!/usr/bin/ruby -w

quiz_data = File.read( ARGV[0] ).split "\n"
questions = []
questions << [quiz_data.shift, quiz_data.shift] while quiz_data.size > 0
questions.shuffle!
questions.each do |q|
print q[0] + " "
STDIN.gets
puts q[1]
puts
end


Save your questions in a text file, one question per line followed by the answer on a separate line. Then invoke the program with “./quiz.rb <filename>”

Ruby is the language for which my knowledge is weakest (of all languages I know at all) - what is the << operator doing and how do you end up shuffling while keeping the questions and answers matching up?

Azrak
Apr 3, 2013, 02:21 PM
I am on a mac. Is it possible for me to use Ruby? How can i do that?
And Ytk what do you mean exactly by "Then invoke the program with “./quiz.rb <filename>” "?

Thanks a lot

ArtOfWarfare
Apr 3, 2013, 04:08 PM
I am on a mac. Is it possible for me to use Ruby? How can i do that?
And Ytk what do you mean exactly by "Then invoke the program with “./quiz.rb <filename>” "?

Thanks a lot

... I'm coming to the conclusion you have virtually no programming experience given you don't know C++, Ruby, or how to use Terminal.

I suggest reading this free ebook and doing the exercises if you're interested in learning how to program with Ruby. I haven't read it, but I've read other books in the series by the same author:

http://ruby.learncodethehardway.org/book/

ytk
Apr 3, 2013, 04:28 PM
Ruby is the language for which my knowledge is weakest (of all languages I know at all) - what is the << operator doing and how do you end up shuffling while keeping the questions and answers matching up?

In this context, << appends to an array. Note that I am appending an array to the main array, with each subarray containing a question/answer pair. So the call to shuffle! (the ! is a Ruby convention that signifies an in-place operation) only shuffles a bunch of arrays, but doesn't break out each individual array. So the question and answer pairs stay synchronized.

chown33
Apr 3, 2013, 06:39 PM
When is the history exam? That date will determine the deadline date for making the quiz program. Having a program too close to, or even after, the exam date is worthless. One needs sufficient time to actually use the program to learn the material.

If the deadline is anything less than maybe a month away, you should probably forget about writing a program. It seems like writing a program would be a significant diversion from the actual goal, which is studying history. In particular, all the time spent getting the program to work does nothing to help you memorize any history material.

Instead of a quiz program, maybe make "flashcards" with the question on one side and the answer on the reverse. This is fairly easy to do in a word-processor, where you layout the questions on one page, and put the answers opposite the question on the next page. Print it on card stock (visit an office-supply store) using a double-sided (duplexing) printer, and the answers will end up on the reverse sides of the questions. I recommend printing a trial run on plain paper first, to confirm that print settings, layout, etc. are correct. Then cut apart with scissors or a paper cutter, shuffle, and use.

The page layout of questions and answers can be reused fairly easily with any number of new questions and answers. There may even be specialized apps that let you make your own flashcards, either printed or entirely computerized. If you insist on having a program to do this, I'd start by looking for apps with those keywords: flash card or flashcard.

http://en.wikipedia.org/wiki/Flashcard

ChrisA
Apr 3, 2013, 07:11 PM
What do you mean by

I will create all my questions and associate an answer to each question.
I want the program to ask me those questions in a random order and prompt me to type the answer. After i type my answer i want the program to show me the correct answer whether or not my answer is correct.

Just a minute. If it ignores what you type this is TRIVIAL Here is the logic.

1) Set N to (random number) * 2 - 1

2) Display text number "N"

3) accept any input and discard it with no processing

4) display text number N+1

5) go to #1

Set up the data file so that odd numbered records are questions and even numbers are answers.

----------

I am on a mac. Is it possible for me to use Ruby? How can i do that?
And Ytk what do you mean exactly by "Then invoke the program with “./quiz.rb <filename>” "?

Thanks a lot

Hate to say but if you have to ask about what is "./quiz.rb" then you are NOT going to be able to write a program of any kind. That question is as basic as it gets. You will have some months of study before you can do this yourself.

Why not buy a pack of 200 index cards at the dollar store and be done with this?

ytk
Apr 4, 2013, 01:05 AM
Aaaand here's the same code as a one-liner, just for fun: :)

#!/usr/bin/ruby -w

File.read( ARGV[0] ).split("\n").each_slice(2).to_a.shuffle.each{ |x| puts x[1] if STDIN.gets unless print x[0] + " " }

AtariMac
Apr 4, 2013, 07:52 AM
You really ought to do it in Scratch. It is very powerful for those with no programming experience.

My 12 year old son won a regional programming contest making a game in Scratch.

If he can do it, so can you.

ArtOfWarfare
Apr 4, 2013, 10:18 AM
You really ought to do it in Scratch. It is very powerful for those with no programming experience.

My 12 year old son won a regional programming contest making a game in Scratch.

If he can do it, so can you.

I dislike things like Scratch. They have their limitations, and once you hit them, you're back to square 1: needing to know an actual programming language.

That or you end up doing convoluted things just to work around the limitations. You're better off learning some actual programming languages.

At 12, I was learning C. I taught myself C before I learned Algebra (and it helped immensely with understanding variables and functions.)

AtariMac
Apr 4, 2013, 11:53 AM
I dislike things like Scratch. They have their limitations, and once you hit them, you're back to square 1: needing to know an actual programming language.

That or you end up doing convoluted things just to work around the limitations. You're better off learning some actual programming languages.

At 12, I was learning C. I taught myself C before I learned Algebra (and it helped immensely with understanding variables and functions.)

I do not disagree with your thinking, but I'm not sure the OP is really interested in programming as a career choice. I think he/she just wants to make a quiz.

Scratch is very well suited for making a quiz.

And as for variables, Scratch has great support.

Azrak
Apr 4, 2013, 03:34 PM
I'm sorry guys I didn't think it would be that complicated to create a program with a bit of your help.

I'm not sure the OP is really interested in programming as a career choice.
I actually am interested in programming, i'm thinking of applying for software engineering for college. I also do have a bit of experience in programming, but not enough to create my own program, I guess. I've learned a bit of xcode, visual basic and java u but only the basics. My priority now is actually my quiz, so i did try out Scratch. It worked pretty well, i finally create my quiz and it's up and working. The only thing that is missing for my quiz is that I can't make the questions asked in a random order, it is always asked in the same order from a to z. It's not a big deal though, I'm fine with my quiz.

Thanks a lot.

chown33
Apr 4, 2013, 09:07 PM
... I also do have a bit of experience in programming, but not enough to create my own program, I guess. ... so i did try out Scratch. It worked pretty well, i finally create my quiz and it's up and working.

I don't understand this: "not enough to create my own program, I guess." You apparently wrote a program, and it's working, so based on that, you do have enough experience to create your own program. It may not do everything you wanted (yet), but the fact that you were able to learn a new language (Scratch) and write a program with it says a lot.


The only thing that is missing for my quiz is that I can't make the questions asked in a random order, it is always asked in the same order from a to z. It's not a big deal though, I'm fine with my quiz.

Read this:
http://www.mikeash.com/getting_answers.html

Points 1-3 are especially relevant.

AtariMac
Apr 5, 2013, 07:50 AM
My priority now is actually my quiz, so i did try out Scratch. It worked pretty well, i finally create my quiz and it's up and working. The only thing that is missing for my quiz is that I can't make the questions asked in a random order, it is always asked in the same order from a to z. It's not a big deal though, I'm fine with my quiz.

Thanks a lot.

You can randomize using a script like the attached image.

Hans Kamp
Apr 5, 2013, 07:59 AM
It is an interesting program. The screenshot shows, that you can program it, although there is no programming language, nor with a syntax and grammar and so on.

Quartz Composer is something similar.

Azrak,

I think you have to dive into the possibilities of Scratch.

Azrak
Apr 5, 2013, 09:10 AM
You can randomize using a script like the attached image.

Wow! That's exactly what i needed! Thanks a lot!

AtariMac
Apr 5, 2013, 09:59 AM
Wow! That's exactly what i needed! Thanks a lot!

Glad to help. If you need any more advice let me know.

Azrak
Apr 6, 2013, 09:53 AM
Actually there is more to my scratch quiz than i thought.
I have 18 questions and every time i start the program it asks me questions in a random order. How do I make it so it asks me the questions without repeating one? I mean if it already asked me question 4 i don't want it to ask me that question again.

I set my variable "random" to pick a random number from 1 to 18 (I have 18 questions. How do it so next time "random" picks a random number from 1 to 18, it doesn't pick the last(s) number(s) previously picked?

ArtOfWarfare
Apr 6, 2013, 10:13 AM
Actually there is more to my scratch quiz than i thought.
I have 18 questions and every time i start the program it asks me questions in a random order. How do I make it so it asks me the questions without repeating one? I mean if it already asked me question 4 i don't want it to ask me that question again.

I set my variable "random" to pick a random number from 1 to 18 (I have 18 questions. How do it so next time "random" picks a random number from 1 to 18, it doesn't pick the last(s) number(s) previously picked?

Keep an array of previously picked numbers and make sure the new number isn't on the list. Or do what I suggested and actually shuffle the cards. These may not be possible or unnecessarily difficult on account of the fact you've chosen Scratch.

Azrak
Apr 6, 2013, 10:22 AM
Keep an array of previously picked numbers and make sure the new number isn't on the list. Or do what I suggested and actually shuffle the cards. These may not be possible or unnecessarily difficult on account of the fact you've chosen Scratch.

Well Scratch is a very easy thing to use to people who don't have much experience, like me.

AtariMac, since you're familiar with Scratch, do you know if it is possible to use an array? Or an alternative way to do what i need?

Azrak
Apr 6, 2013, 10:44 AM
Nevermind! an array on Scratch is called a list.

Azrak
Apr 6, 2013, 11:20 AM
I create a list (or array) called "unique".
Every time the program asks me a question, i insert the question number into the list "unique".
How can i set my variable "random" to pick a number between 1 and 18 that isn't in the list "unique"? I tried:
set random [pick a number between 1 and 18] - unique.
But that didn't work.

AtariMac, think you can help?

chown33
Apr 6, 2013, 11:56 AM
Alternative strategy:

Keep a list of unasked questions. Call it 'unasked'.

Keep a list of asked questions. Call it 'asked'. It starts out empty.

Pick a random number for however many questions remain in 'unasked'. Ask that question. Remove it from 'unasked', and add it to 'asked'.

Repeat until 'unasked' is empty, then start over.

ArtOfWarfare
Apr 6, 2013, 01:10 PM
Alternative strategy:

Keep a list of unasked questions. Call it 'unasked'.

Keep a list of asked questions. Call it 'asked'. It starts out empty.

Pick a random number for however many questions remain in 'unasked'. Ask that question. Remove it from 'unasked', and add it to 'asked'.

Repeat until 'unasked' is empty, then start over.

What's the point of 'asked'?

chown33
Apr 6, 2013, 02:25 PM
What's the point of 'asked'?

To avoid rereading the file. At any point, the complete set of questions is the union of 'asked' with 'unasked'.

ravenvii
Apr 6, 2013, 07:30 PM
Yet another alternative solution:

while number in unique list:
unique = generate new random number

AtariMac
Apr 6, 2013, 08:30 PM
I create a list (or array) called "unique".
Every time the program asks me a question, i insert the question number into the list "unique".
How can i set my variable "random" to pick a number between 1 and 18 that isn't in the list "unique"? I tried:
set random [pick a number between 1 and 18] - unique.
But that didn't work.

AtariMac, think you can help?

Try something like this attached image:

Azrak
Apr 7, 2013, 03:48 AM
Try something like this attached image:

Wow! great thinking! My quiz is finally 100% built!
Thanks a ton

Hans Kamp
Apr 7, 2013, 06:02 AM
AtariMac,

It looks like a programming language, only the appearance is awesome graphically, IMO. It would be a very little step to translate this into Xcode or another structured programming language.

As shown here, you can use a flag which is NO when a question has not been asked yet, and YES when it has.

AtariMac
Apr 7, 2013, 07:25 AM
AtariMac,

It looks like a programming language, only the appearance is awesome graphically, IMO. It would be a very little step to translate this into Xcode or another structured programming language.

As shown here, you can use a flag which is NO when a question has not been asked yet, and YES when it has.

I really like Scratch and the Berkeley variant SNAP! I realize that it is not for everyone, but it reminds me of the early days of personal computing when BASIC was included with every machine.

In fact, Scratch's syntax is very similar to BASIC. It is object oriented though, so each sprite or background can run independently or together. It is great for making 2D games as it has support for players, missiles, and collision detection.

For anyone that wants the satisfaction of making a computer do what you want rather than just doing what someone else wants the computer to do Scratch is a great gateway.

Hans Kamp
Apr 10, 2013, 12:48 AM
I may want to learn it. I have something with languages, whether they are programming languages like C or Xcode, natural languages like German or Afrikaans or artificial langages like Esperanto or Interlingua... :)

ArtOfWarfare
Apr 10, 2013, 08:07 AM
programming languages like c or xcode

¡¡¡XCODE is NOT a PROGRAMMING LANGUAGE!!!

Xcode is an Integrated Development Environment (IDE). It bundles together several components for doing various programming related tasks. It includes tools for doing research, linking libraries, writing code, compiling code, debugging code, running code, making executables, signing executables, and uploading executables to Apple.

It supports many languages for its code related tasks, including C, Obj-C, C++, Obj-C++, and JS.

Trying to say that Xcode is a language is like saying that paper and pencil is a language, or that TextEdit, Word, Pages, or any other text editor is a language. It is not a language! It is a tool that helps you do any number of programming tasks in any number of programming languages. It is not itself a programming language.

I'll say it one more time (just because copy and paste is so easy,):

¡¡¡XCODE is NOT a PROGRAMMING LANGUAGE!!!

ravenvii
Apr 10, 2013, 08:10 PM
Just to go along with the upside exclamation points:


¡¡¡XCODE NO es un LENGUAJE DE PROGRAMACION!!!

JordenLouis
May 23, 2013, 04:28 AM
I had to say I got something really meaningful here which I was searching for so long. Thanks buddy for bringing this out here.