lundi 9 octobre 2017

Group if-else statement then execute a random set

I'm making a program that will generate a random trivia quiz, which, in each question contain if-else statement and variables. Need to know how can I group each set and generate a random set each time, with import random or please suggest me if there's another way to do this.

my code:

c1 = 0
c2 = 0
while(1):
  quiz1 = print("What is Prosciutto?")
  q = input().lower()
  if ("italian" in q) or ("dry" in q) or ("ham" in q):
    print("Correct!")
    c1 +=1
  else:
    print("Not quiet right, Prosciutto is Italian dry-cured ham")
    c2 +=1
  input("Press Enter to continue...")
  quiz2 = print("What is the capital of the US state of Alabama?")
  q = input().lower()
  if "montgomery" in q:
    print("Correct!")
    c1 +=1
  else:
    print("Nope, Montgomery, it is.")
    c2 +=1
  input("Press Enter to continue...")
  quiz3 = print("Which planet spins on a nearly horizontal axis?")
  q = input().lower()
  if "uranus" in q:
    print("Correct!")
    c1 +=1
  else:
    print("Actually it is Uranus!")
    c2 +=1
  input("Press Enter to continue...")
  quiz4 = print("Who invented writing?")
  q = input().lower()
  if "sumerian" in q:
    print("Correct!")
    c1 +=1
  else:
    print("Nope, the Sumerians invented writing")
    c2 +=1
  input("Press Enter to continue...")
  quiz5 = print("What rapper was born Marshall Bruce Mathers III?")
  q = input().lower()
  if "eminem" in q:
    print("Correct!")
    c1 +=1
  else:
    print("He's Eminem")
    c2 +=1
  input("Trivia ended, Press Enter to view your result...")
  break
print("You've made", c1, "corrects answers and ", c2, "wrong answers")

Aucun commentaire:

Enregistrer un commentaire