Python Quiz Showcase
Using my python quiz
import getpass, sys
# This creates the function that I'll be using to create the quiz
def question_and_answer(prompt):
print("Question: " + prompt)
msg = input()
print("Answer: " + msg)
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
# This creates the variables that will be used to calculate score
questions = 5
correct = 0
# Introduces user to quiz
print('Hello, ' + getpass.getuser() + " running " + sys.executable)
print("You will be asked " + str(questions) + " questions.")
question_and_answer("Are you ready to take a test?")
# Starts quiz
rsp = question_with_response("What is 9+9")
if rsp == "18":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("What is my favorite electronic device")
if rsp == "computer":
print(rsp + " is correct!")
correct += 1
else:
print(rsp + " is incorrect!")
rsp = question_with_response("Do you have any pets?")
if rsp == "Yes":
print("Yes? That's nice!")
correct += 1
else:
print("hrm, cool")
correct += 1
rsp = question_with_response("Is this a fun quiz?")
if rsp == "no":
print(rsp + " is correct!")
correct += 1
else:
print("herm")
correct += 1
rsp = question_with_response("I'll let you go free now, are you enthused?")
if rsp == "Yes":
print("hee, rude")
correct += 1
else:
print("welp")
correct += 1
# Tells user their score
print(getpass.getuser() + " you scored " + str(correct) +"/" + str(questions))
from random import seed
from random import randint
# Introducing what will be happening to a bored audience
print("Hey, I'm trying out python, let's experience this quick simple story together!")
print("Note: As you go through this journey remember to only respond with 'Yes' or 'No'")
def question_with_response(prompt):
print("Question: " + prompt)
msg = input()
return msg
# Using variables for choices that I'll be creating
choice_1 = 0
choice_2 = 0
choice_3 = 0
choice_4 = 0
choice_5 = 0
random = 0
# Starting the choices
print("Today, you wake up, a day filled with possibilities, it is softly drizzling outside, and you slept a full 6 hours ")
rsp = question_with_response("Now, do you get up and shower?")
if rsp == "Yes":
choice_1 = 1
print("The shower is nice and refreshing, washing of a night's worth of stink")
elif rsp == "No":
choice_1 = 0
print("You lay in your bed, wallowing in a bit of stink, it felt like a lazy day")
else:
print("Remember that your choices have to be 'Yes' or 'No' exactly, your future is a mystery")
random = randint(0,1)
choice_1 = random
rsp = question_with_response("Breakfast is in order, is it worth it to make it?")
if rsp == "Yes":
choice_2 = 1
print("You make your favorite breakfast, and it turned out above par, you feel happy")
elif rsp == "No":
choice_2 = 0
print("You're still a bit full from eating two steaks last night, so you decide not to, although feel a bit like you're missing out")
else:
print("Remember that your choices have to be 'Yes' or 'No' exactly, your future is a mystery")
random = randint(0,1)
choice_2 = random
rsp = question_with_response("Time to decide what you're doing today, is it work time?")
if rsp == "Yes" :
choice_3 = 1
print("You make your favorite breakfast, and it turned out above par, you feel happy")
elif rsp == "No":
choice_3 = 0
print("You're still a bit full from eating two steaks last night, so you decide not to, although feel a bit like you're missing out")
else:
print("Remember that your choices have to be 'Yes' or 'No' exactly, your future is a mystery")
random = randint(0,1)
choice_3 = random
# Import random number generator
from random import randint
# Defining my variables here
score = 0
online = True
# Use a dictionary for the questions
quesDict = {
0: "What is the tallest mountain in the world",
1: "What is 2+5?",
2: "What programming language was used to make this quiz?",
3: "How many programming languages does the creator of this quiz know?",
4: "What is the favorite coding part of python for the creator of this quiz?",
5: "What is a nice little tune?",
6: "Tick?",
}
# Use a dictionary for the correct solutions
soluDict = {
0: "Mount Everest",
1: "7",
2: "Python",
3: "0",
4: "Variables",
5: "Ladaradadeedoo",
6: "Tock",
}
print("When playing this game, you will go through a list of 7 questions in a randomized order, if you get a question wrong the test is over and you get your final score, good luck! \n")
while online:
index = randint(0, 6)
print(quesDict.get(index) + "\n")
guess = input()
if(guess == soluDict.get(index)):
score+=1
print("Correct! Score: " + str(score))
else:
print("Incorrect! The correct answer was " + soluDict.get(index) + ", Final score: " + str(score))
online = False
# Defining my variables here
score = 0
quesAmou = -1
# Use a dictionary for the questions
quesDict = {
0: "What is the tallest mountain in the world",
1: "What is 2+5?",
2: "What programming language was used to make this quiz?",
3: "How many programming languages does the creator of this quiz know?",
4: "What is the favorite coding part of python for the creator of this quiz?",
5: "What is a nice little tune?",
6: "Tick?",
}
# Use a dictionary for the correct solutions
soluDict = {
0: "Mount Everest",
1: "7",
2: "Python",
3: "0",
4: "Variables",
5: "Ladaradeedoo",
6: "Tock",
}
print("When playing this game, you will go through a list of 7 questions, remember to capitalize your answers and do your best!")
while quesAmou <= 5:
quesAmou += 1
print(quesDict.get(quesAmou) + "\n")
guess = input()
if(guess == soluDict.get(quesAmou)):
score+=1
print("Correct! Score: " + str(score))
else:
print("Incorrect! The correct answer was " + soluDict.get(quesAmou) + "\n")
print("Final score: " + str(score))