Python Quiz
Vocabulary quiz testing python terms!
import getpass
def q_w_r(question, answer):
print(question)
res = input(question)
if res == answer:
print(res + " is correct! Nice job.")
points = 1
else:
print("Sorry that's not right. Next question!")
points = 0
return points
questions = 4
score = 0
print('Hello, ' + getpass.getuser() + "! Welcome to my quiz. :)")
print("Do you want to take the quiz? (y/n)")
reply = input("Do you want to take the quiz? (y/n)")
if reply == "n":
print("Alright then, have a nice day!")
quit()
else:
print("Alright! You will be asked " + str(questions) + " questions about python terms. Let's get started!")
#questions 1-4
score += q_w_r("Q1: What symbol do you use to concatinate/combine two strings?:", "+")
score += q_w_r("Q2: How do you check if a string consists of all lowercase letters?:", "islower" )
score += q_w_r("Q3: What function do you use to get user input?:", "input")
score += q_w_r("Q4: How do you define a function or method?:", "def")
print("Nice try, " + getpass.getuser() + "! You scored " + str(score) +"/" + str(questions) + " on this quiz.")