Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Azrak

macrumors newbie
Original poster
Apr 2, 2013
11
0
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
 
Last edited:

Hans Kamp

macrumors member
Mar 24, 2013
38
0
Enschede, Netherlands
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

macrumors G3
Nov 26, 2007
9,560
6,059
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

macrumors newbie
Original poster
Apr 2, 2013
11
0
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

macrumors newbie
Original poster
Apr 2, 2013
11
0
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.
 

ytk

macrumors 6502
Jul 8, 2010
252
5
What language are you trying to do this in?

Here's a program that will do it in Ruby:
Code:
#!/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

macrumors G3
Nov 26, 2007
9,560
6,059
What language are you trying to do this in?

Here's a program that will do it in Ruby:
Code:
#!/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

macrumors newbie
Original poster
Apr 2, 2013
11
0
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

macrumors G3
Nov 26, 2007
9,560
6,059
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

macrumors 6502
Jul 8, 2010
252
5
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

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
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

macrumors G5
Jan 5, 2006
12,576
1,691
Redondo Beach, California
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

macrumors 6502
Jul 8, 2010
252
5
Aaaand here's the same code as a one-liner, just for fun: :)

Code:
#!/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

macrumors regular
Mar 10, 2004
191
89
Southeastern, PA
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

macrumors G3
Nov 26, 2007
9,560
6,059
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

macrumors regular
Mar 10, 2004
191
89
Southeastern, PA
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

macrumors newbie
Original poster
Apr 2, 2013
11
0
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

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
... 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

macrumors regular
Mar 10, 2004
191
89
Southeastern, PA
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.
 

Attachments

  • scratch.jpg
    scratch.jpg
    37.9 KB · Views: 978

Hans Kamp

macrumors member
Mar 24, 2013
38
0
Enschede, Netherlands
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

macrumors newbie
Original poster
Apr 2, 2013
11
0
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

macrumors G3
Nov 26, 2007
9,560
6,059
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.