So, I have this script that I am using to study some Biology vocab words for my final tomorrow. All I did was put the list of words/definitions in my existing script, and everything seems to go wrong. I have a total of 50 definitions, yet it says there are only 6.

Simplified code:

#!/usr/bin/python

words = {"a":"The placing of sperm cells in the oviducts of the females is called\na. internal fertilization\nb. milting\nc. spawning\nd. moting\ne. external fertilization\nf. tremendously invigorating",
	     "c":"The brain region which controls the coordinates muscular activity\na. medulla oblongata\nb. cerebrum\nc. cerebellum\nd. optic lobe\ne. brain stem",
	     "c":"brain region which attaches brain to spinal column and controls internal organs\na.cerebellum\nb.cerebrum\nc. medulla oblongata\nd. hypothalamus",
	     "c":"the sac that stores the fluid cellular wastes of the body\na.gall bladder\nb. medulla oblongata\nc. urinary bladder\nd. villi\ne. mesentary",
	     "f":"The muscle that divides the abdominal and thoracic cavities in mammals is the\na. rugae\nb. tricep\nc. bicep\nd. caecum\ne. peritenium\nf. diaphragm",
	     "e":"The organ that allows exchange of materials between the embryo and mother in mammals is the\na. dura mater\nb. amnion\nc. yolk\nd. chorion\ne. placenta\nf. none of the above",
	     "e":"The reason for the testes being carried in the scrotum outside of the body is\na. for looks\nb. to decrease sperm production\nc. to increase the production of sperm\nd. unknown to scientists\ne. temperature regulation",
	     "d":"One characterist all mammals have in common is that\na. they are terestrial\nb. they have large brains\nc.they bear live young\nd. their young are nourished by milk\ne. all of these",
	     "e":"the largest brain region in mammals -- it controls memory -- is\na.dura mater\nb. medulla oblongata\nc.Cerebellum\nd. Cranial\ne. cerebrum",
	     "c":"The 'Wind Pipe' or tube which runs from the throat to the lungs\na. aorta\nb. Larynx\n. Trachea\nd. esophagus\ne. diaphragm",
	     "c":"Microscopic projections of the wall of the small intestine tha tincrease the absorbing surface are called\na. vibrissae\nb. rugae\nc. villi\nd. pylorus\ne. caecum",
	     "d":"The thin tough membrane which lines the abdominal cavity\na. pericardium\nb. caecum\nc. dura mater\nd. peritoneum",
	     "e":"Bile is stored in this sack-like structure\na. vena cava\nb. spleen\nc. pancreas\nd. pericardium\ne. gall bladder",
	     "e":"Membrane that surrounds the heart\na. vena cava\nb. messentary\nc. nicitating membrane\nd. tympanic membrane\ne. pericardium",
	     "e":"The food tube in the pig, connects the pharynx to the stomach is called the\na. spleen\nb. glottis\nc. pancreas\nd. vena cava\ne. esophagus",
	     "a":"The ribbon-like organ which functions in the circulatory system and the immune system it produces and stores many kinds of blood cells and is part of the G.A.L.T. of the immune system\na. spleen\nb. kidney\nc. gallbladder\nd. pancreas\ne. pericardium",
	     "e":"Blood vessels that carry blood away from the heart are\na. ventricles\nb. veins\nc. atria\nd. capillaries\ne. arteries",
	     "d":"The pumping chamber of the heart is the\na. atrium\nb. sinus venosus\nc. aorta\nd. ventricle\ne. atria",
	     "d":"The brain region controlling internal organs\na. cerebrum\nb. optic lobes\nc. olfactory lobes\nd. medulla oblongata\ne. cerebellum",
	     "c":"The body cavity that houses the brain\na. cerebellum\nb. olfactory lobes\nc. crania\nd. carotid\ne. pulmanory",
	     "c":"Vessels which carry blood to and from the lungs\na. cranial\nb. aortic\nc. pumonary\nd. carotid\ne. andromonous",
	     "d":"The organ which has functions including the production of bile and regulation of sugar metabolism\na. cloaca\nb. kidney\nc. bladder\nd. liver\n.e spleen",
	     "e":"In the brain, the center of instinct, emotion, memory, and inelligence in the vertebrates is the\na. cortex\nb. optic lobes\nc. cranium\nd. cerebellum\ne. cerebrum",
	     "b":"The membrane supporting internal organs\na. cloaca\nb. mesentery\nc. nicititating membrane\nd. eustachian tube\ne. amplexus",
	     "d":"Primary excretory organ of mammals\na. glottis\nb.obisac\nc. eustachian tube\nd. kidney\ne. all of these",
	     "a":"The large organ which functions in sugar metabolism and secretes bile\na. liver\nb. kidneys\nc. pancreas\nd. spleen\ne. caecum",
	     "c":"The breathing muscle in mammals\na. spleen\nb. gall bladder\nc. diaphragm\nd. caecum\ne. mesentary",
	     "d":"The small sac-like organ which stores bile\na. spleen\nb. caecum\nc. esophagus\nd. gall bladder\ne. liver\nf. scrotum",
	     "b":"The main artery which leaves the heart and branches out to distribute blood to all parts of the body\na. trachea\nb. aorta\nc. atria\nd. ductus arteriosus\ne. pulmonary",
	     "e":"Throughout vertebrate development, there has been an increase in the relative size of the\na. spinal cord\nb. oral cavity\nc. cerebellum\d. optic lobes\e. cerebrum",
	     "c":"The epiglottis\na. is located in the lung\b. allows mammals to breathe\nc. prevents food from moving into the respiratory passages\nd. is made of bony material",
	     "e":"The tough outer membrane which covers the brain\na. cerebellum\nb. skull\nc. pericardium\nd. Peritoneum\ne. dura mater",
	     "a":"The circulation for and around the heart\na. coronary\nb. pulmonary\c. ductus arteriosus\nd. circulatory\ne. mesentery",
	     "b":"The organ in the fetal pig which is equivalent to the appendix in the man\na. oinker\nb. caecum\nc. trachea\nd. atria\ne. cerebrum",
	     "e":"The cavity which houses the heart and lungs\na. jurrasic\nb. ventricle\nc. abdominal\d. cranial\ne. thoracic",
	     "b":"The 'voice box' or 'Adam's apple'\na. diaphragm\nb. larynx\nc. throat\nd. pharynx\ne. esophagus",
	     "a":"The main large vein which returns blood from the body to the heart\na. vena cava\nb. capillary\nc. spleennd. artery\ne. epiglottis",
	     "e":"Opening into trachea\na. cloaca\nb. nicititating membrane\nc. kidney\nd. eustachian tube\ne. glottis",
	     "e":"Equalizes air pressure in the ears\na. cloaca\nb. kidney\nc. glottis\nd. nicitating membrane\ne. eustachian tube",
	     "a":"Hearing in the pig is aided by a special structures called the\na. tympanic membranes\nb. nicititating membranes\nc. nephrons\nd. eustachian tubes\ne. both B and C are correct",
	     "d":"The pylorus\na. is the second part of the intestine\nb. removes waste products\nc. produces digestive enzymes\nd. is an opening in the stomach\ne. is a sex organ",
	     "c":"The intestines are held in place by a tough membrane called the\na. meninges\nb. tympanum\nc. mesentery\nd. coelom\ne. both A and C are correct",
	     "d":"One of the functions of the large intestine is to\na. produce important hormones\nb. digest additional food\nc. store digested food products\nd. reabsord water from the wastes\ne. all of these are correct",
	     "d":"Excess carbohydrates may be stored in the liver as\na. insulin\nb. glucose\nc. fats\nd. glycogen\ne. none of these are correct",
	     "e":"The cerebellum\na. controls the other parts of the brain\nb. receives impulses for sight\nc. controls instincts\nd. inter[rets smell stimuli\ne. controls movement and muscle coordination",
	     "e":"The egg-producing organ in the pig is the\na. cloaca\nb. testes\nc. colon\nd. seminal vesicles\ne. ovary",
	     "e":"Kidneys deposit waste products into this structure\na. tympanic membranes\nb. gall bladder\nc. duodenum\nd. pancreas\ne. urinary bladder",
	     "e":"Produces insulin and digestive enzymes\na. spleen\nb. bladder\nc. duodenum\nd. tympanic membranes\ne. pancreas",
	     "c":"First section of the small intestines\na. illium\nb. colon\nc. duodenum\nd. pancreas\ne. urostyle",
	     "a":"Bypass vessel which connects the pulmanory artery and the aorta during fetal development\na. ductus arteriosus\nb. caecum\nc. cranial\nd. vena cave\ne. aorta"}

print
for x in words:
    print x
print
print len(words)

The output of running this script is:

a
c
b
e
d
f

6

Does anybody have any idea what stupid mistake I am doing to cause this?

Thanks in advance.

Much sorryness. I just figured out that the words were my problem. All the words were technically the same 6 keys *hits head on desk*. Feel free to delete thread.

Hey, don't be sorry, it's a great approach to a quiz. Now you found out that dictionary keys have to be unique. So, what did you do to correct this?

For the time being, I just changed the keys to the name of the correct answer.

Example:

Instead of

"c":"The brain region which controls the coordinates muscular activity\na. medulla oblongata\nb. cerebrum\nc. cerebellum\nd. optic lobe\ne. brain stem"

I did this:

"cerebellum":"The brain region which controls the coordinates muscular activity\na. medulla oblongata\nb. cerebrum\nc. cerebellum\nd. optic lobe\ne. brain stem"

Also, that brings me to a great question. Currently, I have my script set to check if the user's answer is equal to the key of the dictionary pair. Since I cannot just name the keys "a", "b", etc., is there any other way I could have the user type in only "a" or "b", rather than the entire answer?

EDIT: Re-read the question, realized what you're asking....

qs = { "cerebellum":"The brain region which controls the coordinates muscular activity\na. medulla oblongata\nb. cerebrum\nc. cerebellum\nd. optic lobe\ne. brain stem",
#.... etc
}
#
key, value = qs['cerebellum']
print(value)
usr_inp = raw_input('Your answer: ')
if usr_inp == key[0]:
    print 'Correct!'

Just compare the user input to the first character of the key

Sorry, I realized I was a little unclear about what I was trying to say.

So, that is like what I wanted, but not quite. I wanted to do it so...I think it would be easier to show you.

Membrane that surrounds the heart
a. somepossibleanswer
b. somepossibleanswer
c. somepossibleanswer
d. somepossibleanswer
e. correct answer
f. somepossibleanswer

> e

Correct!

So pretty much, rather than typing in the first letter of the correct answer, I would like to do it in a format where you choose a/b/c/d/e/f.

Sorry for the inconvenience, however I have no idea how I would do this.

I simply added the question number to the key's correct answer letter to make it unique. Also prettied the dictionary a little and gave the short version. Here is an example:

#!/usr/bin/python

# a biology quiz using a dictionary
# some improvements would be:
# count total correct answers
# maybe reloop wrong answers


# key "a1" is a composite of correct answer letter + question number
# this makes the key unique
words = {
"a1":
"""The placing of sperm cells in the oviducts of the females is called
a. internal fertilization
b. milting
c. spawning
d. moting
e. external fertilization
f. tremendously invigorating""",
"c2":
"""The brain region which controls the coordinates muscular activity
a. medulla oblongata
b. cerebrum
c. cerebellum
d. optic lobe
e. brain stem""",
"c3":
"""The brain region which attaches brain to spinal column and controls
internal organs
a. cerebellum
b. cerebrum
c. medulla oblongata
d. hypothalamus""",
"c4":
"""The sac that stores the fluid cellular wastes of the body
a. gall bladder
b. medulla oblongata
c. urinary bladder
d. villi
e. mesentary""",
"f5":
"""The muscle that divides the abdominal and thoracic cavities in
mammals is the
a. rugae
b. tricep
c. bicep
d. caecum
e. peritenium
f. diaphragm"""
}


for key, val in words.items():
    print val
    print '-'*30
    choice = raw_input("Enter your choice letter: ").lower()
    if choice[0] in key:
        print "correct"
    else:
        print "wrong, the correct answer is %s" % key[0]
    print '-'*30

Thanks snee that really helps. I actually have a pretty big script going now. Would it be okay if maybe in a few hours I could post it here and get a little help on it? I am trying to avoid globals, but I have no idea how I could do so when I am using so many different variables in different functions.


Membrane that surrounds the heart
a. somepossibleanswer
b. somepossibleanswer
c. somepossibleanswer
d. somepossibleanswer
e. correct answer
f. somepossibleanswer

> e

Correct!

One way is to use 2 dictionaries. The first uses "membrane" as the key, pointing to a list with the possible answers. You print/display this list in the form
a. somepossibleanswer
b. somepossibleanswer
c. somepossibleanswer
d. somepossibleanswer
e. correct answer
f. somepossibleanswer
The second dictionary would contain "membrane" as the key pointing to "e", the correct answer.

If it not too confusing, you could also use a dictionary pointing to a list of lists. The first list would contain the answers, and the second list would contain the correct answer. In any case, you want to store everything in containers so you can use one function to print and then check for the correct answer.

Thanks for the idea woooee, but I think I'm going to try to stick with one dictionary for now. If I continue to expand on the script, I might end up using two. And thanks for everybody's input. I am leaving tomorrow so I will no longer be able to respond.

Thanks everybody!

This article has been dead for over six months. Start a new discussion instead.