Skip to content

Instantly share code, notes, and snippets.

@MaximeKoitsalu
Created December 4, 2019 08:54
Show Gist options
  • Save MaximeKoitsalu/691d1d075098c04568b75866a37cb5f0 to your computer and use it in GitHub Desktop.
Save MaximeKoitsalu/691d1d075098c04568b75866a37cb5f0 to your computer and use it in GitHub Desktop.
Foo
wrong = 0
answered = 0
program_running = 1
def start_program():
global program_running
user_choice = ""
while program_running:
print_menu()
user_choice = input("Ditt val: ")
if user_choice == "1":
run_game()
elif user_choice == "2":
run_stats()
elif user_choice == "3":
program_running = 0
else:
print("-"*30)
print("Du valde ett ogiltigt alternativ. Var god välj mellan 1-3.")
def run_game():
game_not_finished = 1
print_header('Meny > Frågespel')
while game_not_finished:
question('Question A', 'A')
question('Question B', 'B')
question('Question C', 'C')
print_winner_message()
game_not_finished = 0 # Tar dig ur while loop:en
def run_stats():
global wrong, answered
print_header('Meny > Statistik')
print('Du har svarat på frågorna ' + str(answered) + ' gånger')
print('Du har svarat fel på ' + str(wrong) + ' frågor')
def question(question, answer):
global answered, wrong
not_correct = 1
print(question)
while not_correct:
user_input = str(input("Ditt svar: "))
if user_input == answer:
print_correct()
answered+=1
not_correct = 0 # Tar dig ur while loop:en
else:
print_incorrect()
answered+=1
wrong+=1
def print_correct():
print("Korrekt svarat, snyggt jobbat!")
def print_incorrect():
print("Tyvärr fel svarat, försök igen")
def print_winner_message():
print("Grattis, du har klarat frågespelet!")
def print_header(text):
x = ' '
print('*'*30)
print(x*int((30 - len(text))/2) + text)
print('*'*30)
def print_menu():
print_header('Meny')
print('Val:')
print("1. Frågespel")
print("2. Statistik")
print("3. Avsluta")
start_program()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment