Week 7 Sample Program

posted Nov 18, 2016, 8:04 AM by Attila Lengyel
def score(iCorrectAnswers, iMaxAnswers):
  print("Score:", iCorrectAnswers, "/", iMaxAnswers)
  
def quiz(iQ, sQuestion, sAnswer1, sAnswer2, sAnswer3, sAnswer4, sCorrectAnswer):

  print("Question:", iQ)
  print(sQuestion)
  print("A -",sAnswer1)
  print("B -",sAnswer2)
  print("C -",sAnswer3)
  print("D -",sAnswer4)

  answer = input("Answer:")
  if (answer == sCorrectAnswer):
    print("Correct.")
    return 1
  else:
    print("Incorrect.")
    return 0

print("Hello, are you ready for a quiz?")

iCorrectAnswers = 0

iCorrectAnswers = iCorrectAnswers + quiz(1, "What is the capitol of California?", "Los Angeles", "San Diego", "Sacramento", "San Francisco", "C")
score(iCorrectAnswers, 2)

iCorrectAnswers = iCorrectAnswers + quiz(2, "What is the square root of 16?", "2", "4", "6", "8", "B")
score(iCorrectAnswers, 2)



Comments