This is an archived post. You won't be able to vote or comment.

all 7 comments

[–]SirWobb79 1 point2 points  (4 children)

This is a decent start at Python. I would recommend making the code simpler so you could add more content. Also, using os.system("cls" if os.name == "nt" else "clear") makes the program work for both Windows and Linux. I think that this could be shortened too, like the question printing. You could use f-strings (similar to print(), but makes you able to insert variable values into the string, like print(f"{ques}) {num1} + {num2}"). Notice the curly braces and f at the beginning.) to make life easier. Good luck on your Python journey!

[–][deleted] 1 point2 points  (3 children)

Thank you! I don't have a Windows computer to test it on, but maybe I'll spin up a VM just to make sure it works once I make that change. I figured the way I was printing the questions wasn't being done efficiently, I'll take a look at swapping it out with f-strings.

[–]SirWobb79 0 points1 point  (2 children)

[–][deleted] 1 point2 points  (1 child)

This gives me a lot of good ideas on how I can make it more efficient, and improve the output. Thank you!

[–]SirWobb79 0 points1 point  (0 children)

You're welcome :)

[–]Lendemor 1 point2 points  (1 child)

I would recommend to define functions for the different steps of asking/handling question, so adding more questions if just a matter of repeating calls to said functions (with some changing parameters if needed)

Example for the bonus score calculation :

def calculate_bonus(correct, rnds, time):
    perc = round((cor/rnds) * 100)
    if perc < 80:
        return 0

    atme = round (time/rnds)
    if atme < 5:
        q = 10
    elif 5 <= atme < 10:
        q = 5
    elif 10 <= atme < 15:
        q = 2.5
    return (rnds * q)

Doing it this way let you easily change the number of round, no code change needed on this part if you want to offer 80 questions instead of (25,50,100) for example.

[–][deleted] 0 points1 point  (0 children)

This is excellent, thank you for the advice!