#๐Ÿ”’ Computer Quiz Game review

31 messages ยท Page 1 of 1 (latest)

raw forge
#

Tell me if I can improve.

tender ravenBOT
#

@raw forge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

raw forge
#
import sys
print('"Welcome to my Computer Quiz Game!"')
play = input("Do you want play? ")
if play.lower() != "yes":
    print("Okay! Have a nice day:)")
    sys.exit()
else:
    print("Okay! Lets play:)")
score = 0
question1 = input("What does CPU stands for? ")
if question1.lower() == "central processing unit":
    print("Correct!")
    score += 1
else:
    print("Incorrect!")
question2 = input("What does GPU stands for? ")
if question2.lower() == "graphics processing unit":
    print("Correct!")
    score += 1
else:
    print("Incorrect!")
question3 = input("What does RAM stands for? ")
if question3.lower() == "random access memory":
    print("Correct!")
    score += 1
else:
    print("Incorrect!")
question4 = input("What does LCD stands for? ")
if question4.lower() == "liquid crystal display":
    print("Correct!")
    score += 1
else:
    print("Incorrect!")
question5 = input("What does ROM stands for? ")
if question5.lower() == "read only memory":
    print("Correct!")
    score += 1
else:
    print("Incorrect!")
print(f"You got {score} questions correct!")
print(f"You got {( score / 5 ) * 100}%.")
mossy thunder
#

you're using an f-string so you don't need to cast to str

#

!e

num = 42

print(f"A number is {num}")
tender ravenBOT
#

@mossy thunder :white_check_mark: Your 3.12 eval job has completed with return code 0.

A number is 42
raw forge
#

oh ok

#

done

mossy thunder
#

do you know about functions?

raw forge
#

functions are used to make your code easy

mossy thunder
#

sure yeah

#

you could also use a function instead of repeating the same code ```py
questionx = input(question_here)
if questionx.lower() == answer_here:
print("Correct!")
score += 1
else:
print("Incorrect!")

raw forge
#

ok

mossy thunder
raw forge
#

def

#

?

mossy thunder
raw forge
#

so I can define a function and call it??

mossy thunder
#

I'd simplify your code to something like this:

import sys
print('"Welcome to my Computer Quiz Game!"')
play = input("Do you want play? ")
if play.lower() != "yes":
    print("Okay! Have a nice day:)")
    sys.exit()
else:
    print("Okay! Lets play:)")
score = 0

def ask_question(question, answer):
    user_answer = input(question)
    if user_answer.lower() == answer:
        print("Correct!")
        return 1
    else:
        print("Incorrect!")
        return 0

score += ask_question("What does CPU stand for?", "central processing unit")
# you can write the code for the next 4 questions like this

print(f"You got {score} questions correct!")
print(f"You got {( score / 5 ) * 100}%.")
raw forge
#

ok

mossy thunder
#

it's alright if you don't understand how that works, your code without the functions is pretty good too.

raw forge
#

I understood

#

ok

#

Thanks for your suggestion

#

I will try them

#

Thanks @mossy thunder

mossy thunder
#

no problem

tender ravenBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.

#

๐Ÿ”’ Computer Quiz Game review