#๐ Computer Quiz Game review
31 messages ยท Page 1 of 1 (latest)
@raw forge
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.
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}%.")
you're using an f-string so you don't need to cast to str
!e
num = 42
print(f"A number is {num}")
@mossy thunder :white_check_mark: Your 3.12 eval job has completed with return code 0.
A number is 42
do you know about functions?
functions are used to make your code easy
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!")
ok
you're repeating that code like 5 times, instead of which you could make a function
ok
yes, def is used to define a function
so I can define a function and call it??
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}%.")
ok
it's alright if you don't understand how that works, your code without the functions is pretty good too.
I understood
ok
Thanks for your suggestion
I will try them
Thanks @mossy thunder
no problem
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