Page 1 of 1

Reputation:

# Multiple Choice Testing Program

Posted 03 December 2010 - 08:41 AM

Here is my coding:

```print("Preferred Learning Modality Please type no more than one number whose sentence best describes you.")
print("")

letter_a = 0
letter_b = 0
letter_c = 0
letter_d = 0

def question_j():
print("J. In remembering a pleasant vacation I .. .")
print("	       1. Picture what happened")
print("	       2. Hear what was said or other sounds")
print("	       3. Remember how I felt")
print("	       4. Remember what I did.")
question_ten = int(j)
if question_ten == 1:
letter_a = letter_a + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)
else:
if question_ten == 2:
letter_b = letter_b + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)
else:
if question_ten == 3:
letter_c = letter_c + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)
else:
if question_ten == 4:
letter_d = letter_d + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)
else:
print("")
print("")

def question_i():
print("I. When I teach something to someone I...")
print("	       1. Make diagrams or pictures")
print("	       2. Explain in words or tell them how to do it")
print("	       3. Write down how to do it")
print("	       4. Show them by doing it myself")
question_nine = int(i)
if question_nine == 1:
letter_a = letter_a + 1
question_j()
else:
if question_nine == 2:
letter_b = letter_b + 1
question_j()
else:
if question_nine == 3:
letter_c = letter_c + 1
question_j()
else:
if question_nine == 4:
letter_d = letter_d + 1
question_j()
else:
print("")
print("")

def question_h():
print("H. The books I like to read usually have ..")
print("	       1. Colorful description or illustrations")
print("	       2. Dialogue or lots of facts")
print("	       3. Information about helping or have an emotional theme")
print("	       4. Action stories")
question_eight = int(h)
if question_eight == 1:
letter_a = letter_a + 1
question_i()
else:
if question_eight == 2:
letter_b = letter_b + 1
question_i()
else:
if question_eight == 3:
letter_c = letter_c + 1
question_i()
else:
if question_eight == 4:
letter_d = letter_d + 1
question_i()
else:
print("")
print("")

def question_g():
print("G. When I learn a new word, I best remember by ...")
print("	       1. Seeing it")
print("	       2. Hearing it")
print("	       3. Writing it")
print("	       4. Acting out its meaning")
question_seven = int(g)
if question_seven == 1:
letter_a = letter_a + 1
question_h()
else:
if question_seven == 2:
letter_b = letter_b + 1
question_h()
else:
if question_seven == 3:
letter_c = letter_c + 1
question_h()
else:
if question_ == 4:
letter_d = letter_d + 1
question_h()
else:
print("")
print("")

def question_f():
print("F. In my leisure time I would prefer to ...")
print("	       1. Watch a movie, take photographs or see a sunset.")
print("	       2. Listen to audio tapes or music.")
print("	       3. Draw, knit or read inspirational literature")
print("	       4. Play sports, take a hike, play action video games")
question_six = int(f)
if question_six == 1:
letter_a = letter_a + 1
question_g()
else:
if question_six == 2:
letter_b = letter_b + 1
question_g()
else:
if question_six == 3:
letter_c = letter_c + 1
question_g()
else:
if question_six == 4:
letter_d = letter_d + 1
question_g()
else:
print("")
print("")

def question_e():
print("E. When I enter a room, I first notice...")
print("	       1. The decorating, colors, and what's on the walls.")
print("	       2. If it is noisy or quiet")
print("	       3. If I feel or could feel comfortable in this room.")
print("	       4. If there is lots of activity and room to move around.")
question_five = int(e)
if question_five == 1:
letter_a = letter_a + 1
question_f()
else:
if question_five == 2:
letter_b = letter_b + 1
question_f()
else:
if question_five == 3:
letter_c = letter_c + 1
question_f()
else:
if question_five == 4:
letter_d = letter_d + 1
question_f()
else:
print("")
print("")

def question_d():
print("D. I am most frustrated in the classroom when...")
print("	       1. I can't see the lecturer or blackboard they are working on.")
print("	       2. I can see them but can't hear the lecturer speaking.")
print("	       3. I can see and hear but have nothing with which to write down what they are lecturing about.")
print("	       4. I am in such a cramped space, I can hardly move.")
question_four = int(d)
if question_four == 1:
letter_a = letter_a + 1
question_e()
else:
if question_four == 2:
letter_b = letter_b + 1
question_e()
else:
if question_four == 3:
letter_c = letter_c + 1
question_e()
else:
if question_four == 4:
letter_d = letter_d + 1
question_e()
else:
print("")
print("")

def question_c():
print("C. The thing I remember most about a person is .. .")
print("	       1. What they were wearing.")
print("	       2. The sound of their voice, what they said to me.")
print("	       3. The expression on their face or whether I liked them or not.")
print("	       4. If they were active and enthusiastic.")
question_three = int(c)
if question_three == 1:
letter_a = letter_a + 1
question_d()
else:
if question_three == 2:
letter_b = letter_b + 1
question_d()
else:
if question_three == 3:
letter_c = letter_c + 1
question_d()
else:
if question_three == 4:
letter_d = letter_d + 1
question_d()
else:
print("")
print("")

def question_b():
print("B. I feel I am more receptive to learning if the teacher...")
print("            1. Has a nice appearance and dresses neatly.")
print("	       2. Has a pleasant voice.")
print("	       3. Is considerate, fair and a caring person.")
print("	       4. Is active in lecturing and lets us take frequent breaks.")
question_two = int(B )
if question_two == 1:
letter_a = letter_a + 1
question_c()
else:
if question_two == 2:
letter_b = letter_b + 1
question_c()
else:
if question_two == 3:
letter_c = letter_c + 1
question_c()
else:
if question_two == 4:
letter_d = letter_d + 1
question_c()
else:
print("")
print("")

print("A. In the classroom, I learn best if I can...")
print("	       1. See lots of pictures, diagrams, or videos.")
print("	       2. Hear an interesting lecture or recording.")
print("	       3. Write down notes or work examples on paper.")
print("	       4. Do experiments, hands-on activities or move around.")
question_one = int(a)
if question_one == 1:
letter_a = letter_a + 1
question_b()
else:
if question_one == 2:
letter_b = letter_b + 1
question_b()
else:
if question_one == 3:
letter_c = letter_c + 1
question_b()
else:
if question_one == 4:
letter_d = letter_d + 1
question_b()
else:
print("")
print("")
```

Any help would be greatly apriciated thank you

MOD EDIT: When posting code...USE CODE TAGS!!!

Also, don't use insipid titles like "Need Help!" We KNOW you need help, it's WHY you came here and POSTED!!!

Modified title.

This post has been edited by JackOfAllTrades: 03 December 2010 - 09:17 AM

Is This A Good Question/Topic? 0

## Replies To: Multiple Choice Testing Program

### #2 atraub

• Pythoneer

Reputation: 822
• Posts: 2,198
• Joined: 23-December 08

## Re: Multiple Choice Testing Program

Posted 03 December 2010 - 08:45 AM

This is a problem that people commonly hit when they're familiar with one language and move to python.

```    if question_ten == 1:
letter_a = letter_a + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)
else:
if question_ten == 2:
letter_b = letter_b + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)
else:
if question_ten == 3:
letter_c = letter_c + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)

```

The proper syntax is:

```    if question_ten == 1:
letter_a = letter_a + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)

elif question_ten == 2:
letter_b = letter_b + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)

elif question_ten == 3:
letter_c = letter_c + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)

elif question_ten == 4:
letter_d = letter_d + 1
print(letter_a)
print(letter_B )
print(letter_c)
print(letter_d)

else:
print("")
print("")

```

elif is pythons equivalent to else if.

Good luck in the future!

This post has been edited by atraub: 03 December 2010 - 09:02 AM

• Saucy!

Reputation: 6193
• Posts: 23,920
• Joined: 23-August 08

## Re: Multiple Choice Testing Program

Posted 03 December 2010 - 09:20 AM

This:

Quote

my program is not working

is totally insufficient information for us to help you. You need to tell us EXACTLY what your problems are; if there are errors, post them EXACTLY as they appear. If it is not functioning as you expect, you need to tell us what your expectations are and how the program is not fulfilling them.

And please, use good topic titles and put code IN CODE TAGS!!!

### #4 baavgai

• Dreaming Coder

Reputation: 6247
• Posts: 13,389
• Joined: 16-October 07

## Re: Multiple Choice Testing Program

Posted 03 December 2010 - 09:37 AM

Great crap man! Cut and paste is bad for you:

Just having something like this would trim half your code:
```def showLetters():
print(letter_a)
print(letter_b )
print(letter_c)
print(letter_d)

```

You're doing the same thing over and over again! Make the computer do it. Each question has one title, four questions, and four possible answers. Can you make a function that handles this in a more generic way?

Hint, your main could look something like:
```showQuestion('A', "In the classroom, I learn best if I can...",
["See lots of pictures, diagrams, or videos.",
"Hear an interesting lecture or recording.",
"Write down notes or work examples on paper.",
"Do experiments, hands-on activities or move around."])

showQuestion('B', "I feel I am more receptive to learning if the teacher...",
...

```

### #5 atraub

• Pythoneer

Reputation: 822
• Posts: 2,198
• Joined: 23-December 08

## Re: Multiple Choice Testing Program

Posted 03 December 2010 - 10:05 AM

haha adjusting ALL that code is certainly a good way to learn the danger of copy and paste.

This post has been edited by atraub: 03 December 2010 - 11:19 AM

Reputation:

## Re: Multiple Choice Testing Program

Posted 04 December 2010 - 08:28 AM

JackOfAllTrades, on 03 December 2010 - 08:20 AM, said:

This:

Quote

my program is not working

is totally insufficient information for us to help you. You need to tell us EXACTLY what your problems are; if there are errors, post them EXACTLY as they appear. If it is not functioning as you expect, you need to tell us what your expectations are and how the program is not fulfilling them.

And please, use good topic titles and put code IN CODE TAGS!!!

When I run the program the first question works perfectly but the second question give me an error that says

Traceback (most recent call last):
File "H:\Python\FUN\Right-brain left-brain\Preferred Learning Mocality.py", line 282, in <module>
question_b()
File "H:\Python\FUN\Right-brain left-brain\Preferred Learning Mocality.py", line 258, in question_b
letter_b = letter_b + 1
UnboundLocalError: local variable 'letter_b' referenced before assignment

• Saucy!

Reputation: 6193
• Posts: 23,920
• Joined: 23-August 08

## Re: Multiple Choice Testing Program

Posted 04 December 2010 - 11:36 AM

I would take to heart the suggestions above, but the current problem can be answered by reading this.