I started my Python Journey almost a week ago from now. I had been following a Youtube tutorial earlier, but switched to Harvard's CS50P instead. I decided on making a little Quiz Game with my programming knowledge so far. I know this is a really inefficient way to make one, but I honestly don't know how I could have made it more efficient (I am still fascinated how people ONLY make functions and run a SINGLE main function to run the complete code). I am not yet aware of many important things in Python like Classes as well, hence I didn't use them. Can someone guide me if this code is:
- Good?
- How would you rate it in terms of efficiency?
- How is my progress so far (~8-10 days of learning)?
from time import sleep
score = 0
def fq():
sleep(1)
question(statement,options,correct)
def question(statement,options,correct):
print(statement)
sleep(2)
answer = input(options).lower().strip()
check(answer,correct)
def check(answer,correct):
sleep(1)
if answer == correct:
print("Correct!")
global score
score += 1
else:
print("Incorrect!")
print("Welcome to the Quiz Game!")
choice = input("If you want to play, enter in 'yes', otherwise enter 'no': ").lower().strip()
while choice != "yes" and choice != "no":
choice = input("Invlaid choice, if you want to play, enter in 'yes', otherwise enter 'no': ").lower().strip()
if choice == "yes":
print("Great, lets continue!")
sleep(1)
else:
print("We'll play some time later!")
quit()
print("There will be 10 questions, Good Luck")
sleep(2)
statement = "Q1: Hitler party which came into power in 1933 is known as?"
options = "Enter A for Labour Party, B for Nazi Party, C for Ku-Klux-Clan, D for Democratic Party: "
correct = "b"
fq()
statement = "Q2: In which year of First World War Germany declared war on Russia and France?"
options = "Enter A for 1914, B for 1915, C for 1916, D for 1917: "
correct = "a"
fq()
statement = "Q3: Joule is the SI unit of?"
options = "Enter A for Temperature, B for Pressure, C for Energy, D for Current: "
correct = "c"
fq()
statement = "Q3: The famous wonder of the world is named, The Leaning Tower of _____"
options = "Enter A for Siena, B for Pisa, C for Rome, D for Milan: "
correct = "b"
fq()
statement = "Q4: Which country is known as the 'Land of Rising Sun'?"
options = "Enter A for Japan, B for New Zealand, C for China, D for USA: "
correct = "a"
fq()
statement = "Q5: Which continent has the highest number of countries?"
options = "Enter A for Asia, B for Europe, C for South America, D for Africa: "
correct = "d"
fq()
statement = "Q6: How many rings appear on the Olympics Flag?"
options = "Enter A for 1, B for 3, C for 5, D for 7: "
correct = "c"
fq()
statement = "Q7: Which Planet is the 3rd closest to the Sun?"
options = "Enter A for Earth, B for Mars, C for Jupiter, D for Venus: "
correct = "a"
fq()
statement = "What is the largest planet in out Solar System?"
options = "Enter A for Uranus, B for Saturn, C for Jupiter, D for Mercury: "
correct = "c"
fq()
statement = "What planet is nearest to The Earth?"
options = "Enter A for Venus, B for Mercury, C for Mars, D for Pluto: "
correct = "b"
fq()
statement = "How many sides does a Heptagon have?"
options = "Enter A for 5, B for 6, C for 7, D for 8: "
correct = "c"
fq()
print("You have successfully answered all the questions.")
sleep(2)
print("Lets see what your score is!")
sleep(2)
if score >= 5:
print(f"Your score is {score} out of 10. Well done!")
else:
print(f"Your score is {score} out of 10. You could do better!")