-1

This is my code:

class Question:
  def __init__(self,prompt,answer):
    self.prompt = prompt
    self.answer = answer


#Make the questions.
question_prompts =[
  "Who did Echo fall in love with?\n(a) Poseidon\n(b) Zeus\n(c) Narcissus\n(d) Aphrodite ",
  "What did the nymphs find instead of Narcissus' body?\n(a) A dog\n(b) A flower\n(c) A     hand\n(d) A pile of hair ",
  "Who cursed Echo?\n(a) Athena\n(b) Hades\n(c) Hercules\n(d) Hera ",
  "Where was the place Echo found to live in?\n(a) A cave\n(b) A palace\n(c) A cottage\n(d)     A forest ",
  "Where did Narcissus live?\n(a) A dessert\n(b) A jungle\n(c) A house\n(d) A forest ",
  "What was the last thing that was left of Echo?\n(a) Her voice\n(b) Her Ears\n(c) Her   Mouth\n(d) Her Nose ",
  "What type of nymph was Echo?\n(a) A grass nymph\n(b) A wood nymph\n(c) A water nymph\n(d) An ice nymph ",
  "What was Narcissus hunting when Echo first saw him?\n(a) Rabbit\n(b) Bird\n(c) Fish\n(d) Deer ",
  "What did Narcissus fall in love with?\n(a) Echo\n(b) A deer\n(c) His own reflection\n(d) Echo's reflection ",
  "What was Narcissus's last word?\n(a) Hate\n(b) Love\n(c) Happiness\n(d) Sadness "

]

#Set the answers.
questions = [
  Question(question_prompts[0], "c"),
  Question(question_prompts[1], "b"),
  Question(question_prompts[2], "d"),
  Question(question_prompts[3], "a"),
  Question(question_prompts[4], "d"),
  Question(question_prompts[5], "a"),
  Question(question_prompts[6], "b"),
  Question(question_prompts[7], "d"),
  Question(question_prompts[8], "c"),
  Question(question_prompts[9], "b")


]

#Run the quiz and set the score.
def run_quiz(questions):
  score = 0
  for question in questions:
    answer = input(question.prompt)
    if answer == question.answer:
      score += 1

  #Print the score.
  print("You got " + str(score) + "/" + str(len(questions)) + " Correct!")

run_quiz(questions)

I don't know how to make it recognise uppercase letters as well as lowercase letters.

I've tried putting answer = input(question.prompt).lower and answer = input(question.prompt).upper and neither have worked, they just marked answer I put in as incorrect.

1 Answers1

0

When asking for the user's answer, add .lower() or .upper() to convert the input to lowercase or uppercase, like this:

answer = input(question.prompt).lower()  # or .upper()

In the if statement that checks if the user's answer is correct, also add .lower() or .upper() to the question.answer variable, like this:

if answer == question.answer.lower():  # or .upper()

This will convert the correct answer to lowercase or uppercase, depending on the method you used, and make the comparison case-insensitive so that it accepts both uppercase and lowercase letters as correct.

M.Mevlevi
  • 339
  • 3
  • 16