LPTHW - Ex 34 - Questionnaire Program

I wrote a questionnaire program for this exercise that gives a brief explanation of cardinal and ordinal numbers, asks the questions in the exercise regarding the list then evaluates the answers you input. If anyone wants it when doing this exercise, it’s a bit long.


animals = ['bear', 'python', 'peacock', 'kangaroo', 'whale', 'platypus']

print("""\nFirst a brief explaination of cardinal and ordinal numbers:
the ordinal number is the position of the element in a list, eg. first, second,
third, etc.
the cardinal number begins at 0 and is an unordered number, eg. one, two, three
 """)

print(f"""\nNow I'm going to ask you a series of questions relating to
this list; {animals}""")

print("What is the animal at 1?")
one = input('> ')
print("What is the third animal?")
third = input('> ')
print("What is the first animal?")
first = input('> ')
print("What is the animal at 3?")
three = input('> ')
print("What is the fifth animal?")
fifth = input('> ')
print("What is the animal at 2?")
two = input('> ')
print("What is the sixth animal?")
sixth = input('> ')
print("What is the animal at 4?")
four = input('> ')

print("\n Now, let's see how you did!")

print(f"Question one: You answered {one}")
if one == animals[1]:
    print('Correct Answer!')
else:
    print("Wrong Answer!")
    print(animals[1])
print(f"Question two: You answered {third}")
if third == animals[2]:
     print('Correct Answer!')
else:
    print('Wrong Answer!')
    print(animals[2])
print(f"Question three: You answered {first}")
if first == animals[0]:
    print('Correct Answer!')
else:
    print('Wrong Answer!')
    print(animals[0])
print(f"Question four: You answered {three}")
if three == animals[3]:
    print('Correct Answer!')
else:
    print('Wrong Answer!')
    print(animals[3])
print(f"Question five: You answered {fifth}")
if fifth == animals[4]:
    print('Correct Answer!')
else:
    print('Wrong Answer!')
    print(animals[4])
print(f"Question six: You answered {two}")
if two == animals[2]:
    print('Correct Answer!')
else:
    print('Wrong Answer!')
    print(animals[2])
print(f"Question seven: You answered {sixth}")
if sixth == animals[5]:
    print('Correct Answer!')
else:
    print('Wrong Answer!')
    print(animals[5])
print(f"Question eight: You answered {four}")
if four == animals[4]:
    print('Correct Answer!')
else:
    print('Wrong Answer!')
    print(animals[4])

I hope it’s helpful

1 Like

Cool. Save that file and see how you might reduce the repetition later in the book when you hit methods and/or loops.

1 Like

thank you :slight_smile:

A free service run by Zed A. Shaw for learncodethehardway.org.