Python Forum

Full Version: Coding
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
This is my current code ive started coding again as i stopped for a few years due to mental health ive searched but cant find how to end a quiz when making can anyone help please Thanking all of you
score=0
import sys
import time

def typing_effect(text, speed=0.1):
    for char in text:
        sys.stdout.write(char)
        sys.stdout.flush()
        time.sleep(speed)
text = "Welcome to the homebrew quiz. This will test your knowledge of homebrewing."
typing_effect(text, 0.1)

print("What homebrew is used to mod a ps3/4/5?")
print("A: Goldhen")
print("B: Steam")
print("C: USB Loader GX")
print("D: Goldeneye")
answer = input("What is your answer?")
if answer == "A":
  print("Correct!")
  score=score +1
elif answer == "B":
  print("Incorrect!")
elif answer == "C":
  print("Incorrect!")
elif answer == "D":
  print("Incorrect!")
  def typing_effect(text, speed=0.1):
    for char in text:
        sys.stdout.write(char)
        sys.stdout.flush()
        time.sleep(speed)
text = "Next question!"
typing_effect(text, 0.1)

print("What homebrew can be used to homebrew a Nintendo Wii?")
print("A: T-Rush")
print("B: Valve Index CD1")
print("C: NANDS SYSTEM")
print("D: USB Loader GX")
I would go about it like this:

import sys
import time
 
def typing_effect(text, speed=0.1):
	for char in text:
		sys.stdout.write(char)
		sys.stdout.flush()
		time.sleep(speed)

def present_question (question_list):
	prefix = "_ABCD"
	print ("\n", question_list [0])
	for index in range (1, 5):
		print (f"  {prefix [index]}: {question_list [index]}")
	print ("  Press Enter alone to quit.")

def get_users_answer () -> str:
	acceptable_answers = "ABCDabcd"
	while True :
		test_answer = input ("  Enter your choice.]> ")
		if test_answer == "" : sys.exit ()
		if len (test_answer) == 1 and test_answer in acceptable_answers:
			return test_answer.upper ()
		print ("  That is an invalid answer.")

question_array = [
	["What homebrew is used to mod a ps3/4/5?",
	"Goldhen",
	"Steam",
	"USB Loader GX",
	"Goldeneye",
	"A"],
	["What homebrew can be used to homebrew a Nintendo Wii?",
	"T-Rush",
	"Valve Index CD1",
	"NANDS SYSTEM",
	"USB Loader GX",
	"B"]]

print ("\n" * 13)
typing_effect ("Welcome to the homebrew quiz.\n")
typing_effect ("This will test your knowlege of homebrewing.\n\n")
score = 0
for index in range (len (question_array)):
	present_question (question_array [index])
	users_answer = get_users_answer ()
	if users_answer == question_array [index][5]:
		print ("\n  Correct!")
		score += 1
	else :
		print ("\n  Sorry... Wrong answer :{")

print ("\n Thanks for taking the quiz.")
typing_effect (f" Your score is {score}.\n")
typing_effect (" Good bye now :)\n\n")