###################################################
# Project name: Give & Get #
# Project class: Quiz #
# Author: Mario Sukner #
# Generated: 05.02.25 #
###################################################
import math
import time
"""
# nice greeting before starting
"""
greeting = "Hello, I want to play a game."
print(greeting)
def quiz_cars(player):
start_player = time.time()
"""
# start of the quiz
"""
print(f"\nWelcome {player.upper()} to my quiz \"give & get\" !!\n")
print(" --> The time started counting!! <-- \n")
print("Let start with the first question:")
"""
# call the questions and get the answers
"""
answer1 = questions_1()
answer2 = questions_2()
answer3 = questions_3()
answer4 = questions_4(player)
"""
# defines the game duration in summary for each player
"""
end = time.time()
zeit = end - start_player
zeit2 = round(zeit, 2)
print(f"Time taken: {zeit2} seconds")
"""
# prepares the output text for each player with results
"""
out_text_file = "Quiz: give & get\n" + \
"Player name: " + player.upper() + "\n\n" + \
"question_1: " + answer1.title() + "\n" + \
"question_2: " + answer2.upper() + "\n" + \
"question_3: " + str(answer3) + "\n" + \
"question_4: " + str(answer4) + "\n\n" + \
"Total time: " + str(f"{zeit2} seconds") + "\n\n"
"""
# write the results to a text file, append mode for multiple players
"""
with open("Results_give_&_get.txt", "a") as file:
file.write(out_text_file)
"""
# Function for Question 1 (text)
"""
def questions_1():
while True:
answer1 = input("""\n 1. Which car is not a German car? (please write the correct name)
A) Audi
B) BMW
C) Renault
D) Porsche
answer --> """).lower()
if answer1 == "renault":
print("\nYES, that is correct -Renault-, bravo!\n")
print("next question \n")
return answer1
else:
print("Sorry, that is the wrong answer, please try again.")
"""
# Function for Question 2 (text)
"""
def questions_2():
while True:
answer2 = input("""2. Which brand produced the first electrical car? (please choose the correct letter)
A) Ford
B) Tesla
C) Ferrari
answer --> """).lower()
if answer2 == "b":
print("\nYES, the \"Tesla\" company produced the 1st electrical car in 1966.\n")
print("next question \n")
return answer2
elif answer2 == "a":
print("That is not correct, please re-try.\n")
elif answer2 == "c":
print("That is not correct, please re-try.\n")
else:
print("You made a typo, please choose one of the offered letters: A, B or C\n")
"""
# Function for Question 3 (float)
"""
def questions_3():
while True:
try:
answer3 = float(input("""3. Porsche 918 Spyder is speeding up from 0 to 100 km/h in...
A) 2.8 sec
B) 3.8 sec
C) 4.8 sec
answer --> """))
if answer3 == 2.8:
print("Please try again!\n")
elif answer3 == 3.8:
print("\nYes, correct, in 3.8 seconds speeds the Spyder up to 100 km/h.\n")
print("next question \n")
return answer3
elif answer3 == 4.8:
print("Please try again!\n")
else:
print("float must be given!\n")
except ValueError:
print("Please enter a valid float\n")
"""
# Function for Question 4 (int)
"""
def questions_4(player):
colours = ["black", "white", "blue", "red", "purple", "yellow"]
print("4. " + player.title() + ", " + f"Which colours are the most popular for Ferrari?")
for key, name in enumerate(colours):
print(key, ":", name)
while True:
try:
answer4 = int(input("Please type one of the given numbers, 2 answers can be correct --> "))
if answer4 == 3 or answer4 == 5:
print("\nRED and YELLOW are the most popular colours for Ferrari ;)\n")
print(" --the quiz is finished -- \n")
return answer4
elif answer4 == 0 or answer4 == 1 or answer4 == 2 or answer4 == 4:
print("Yes, it is possible but rarely, most popular colours are...\n")
elif answer4 >= 6:
print("you are really persistent, the possible number should be 0-5, let's try one more time...\n")
except ValueError:
print("Please enter a valid integer\n")
"""
# Function that asks if the user wants to continue with another player or quit the game
"""
def play_again():
while True:
play_again_input = input("Do you want to play again with a new player? (yes/no): ").lower()
if play_again_input == "yes":
return True
elif play_again_input == "no":
print("******************************\nThank you for playing! Have a nice day ;)\n******************************""")
return False
else:
print("\nInvalid input. Please type 'yes' or 'no'.\n")
"""
# Main game loop for multiple players (restarts quiz or exits loop and ends program)
"""
def main_givenget():
while True:
player = input("Please enter your name: ")
quiz_cars(player)
"""
# asks if another player wants to play or not
"""
if not play_again():
break
"""
# Start the game
"""
start = time.time()
main_givenget()