python quiz code code example

Example 1: simple trivia question python

ans = input('1. questoin here\n')
if ans.lower() == 'answer to questoin here':
  print("corect")
else:
  print("incorect")

Example 2: python quiz

score = 0
score = int(score)

#Ask user for their name
name = input("What is your name?")
name = name.title()
print("""Hello {}, welcome to Quiz night! 
You will be presented with 5 questions.
Enter the appropriate number to answer the question
Good luck!""".format(name))

#Question1
print("""Question here
1.  
2.  
3.  
4. """)

answer1 = "correct number here"
response1 = input("Your answer is: ")

if (response1 != answer1):
    print("Sorry, that is incorrect!")
else:
    print("Well done! " + response1 + " is correct!")
    score = score + 1

print("Your current score is " + str(score) + " out of 5")

#Question2
print("""What is the name of the town your character lives in before The Great War?
1. Diamond City 
2. Sanctuary Hills 
3. Concord 
4. The Glowing Sea""")

answer2 = "correct number here"
response2 = input("Your answer is:")

if (response2 != answer2):
    print("Sorry, that is incorrect!")
else:
    print("Well done! " + response2 + " is correct!")
    score = score + 1

print("Your current score is " + str(score) + " out of 5")

#Question3
print("""Question here
1.  
2.  
3.  
4. """)

answer3 = "correct number here"
response3 = input("Your answer is:")

if (response3 != answer3):
    print("Sorry, that is incorrect!")
else:
    print("Well done! " + response3 + " is correct!")
    score = score + 1

print("Your current score is " + str(score) + " out of 5")

#Question4
print("""Question here
1. 
2. 
3. 
4. """)

answer4 = "correct number here"
response4 = input("Your answer is:")

if (response4 != answer4):
    print("Sorry, that is incorrect!")
else:
    print("Well done! " + response4 + " is correct!")
    score = score + 1

print("Your current score is " + str(score) + " out of 5")

#Question5
print("""Question here
1. False
2. True""")

answer5 = "correct number here"
response5 = input("Your answer is:")

if (response5 != answer5):
    print("Sorry, that is incorrect!")
else:
    print("Well done! " + response5 + " is correct!")
    score = score + 1

print("Your total score is " + str(score) + " out of 5")
print("Thank you for playing {}, goodbye!".format(name))