Python Forum

Full Version: Increasing difficulty of a maths game
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I am a year 8 student. I am currently undertaking a task in media, where I have to create a maths game. I am allowed to get complex with my code as I like, I just have to be able to understand it. I have been trying to make the difficulty get harder as you progress through the game. I want the code to have 5 levels of difficulty.

Here is my code so far:

def main():
    from random import randint
        
    def dis_intro():
            title = ("** Maths Quiz **")
            print("*" * len(title))
            print(title)
            print("*" * len(title))
        
    def dis_menu():
            title = ("** A Simple Maths Quiz**")
            men_list = ["1. Addition (+)", "2. Subtraction (-)", "3. Multiplication (×)", "4. Division(÷)"]
            print(men_list[0])
            print(men_list[1])
            print(men_list[2])
            print(men_list[3])
            print("-" * len(title))
            
    dis_intro()
    dis_menu()
    
    math_type = int(input("Select one of the options from the menu:"))
    
    QNum = 1
    Score = 0
        
    if math_type == int(1):
        print("Addition! Excelent let's get started right away")
        while QNum <= 5:
            Num1 = randint(1,10)
            Num2 = randint(1,10)
            QAns = Num1 + Num2
            print("")
            print("Q." + str(QNum))
            ans = int(input("What is " + str(Num1) + " + " + str(Num2) + " " + "="))
            P_Ans = str(input)
            if ans == QAns:
                print("Correct")
                print("Well Done")
                print("You earnt 100 points")
                Score = Score + 100
                QNum = QNum + 1
            elif ans != QAns:
                print("Incorrect")
                print("Bad luck")
                print("You earned 0 points")
                Score = Score
                QNum = QNum + 1
        else:
            print("")
            print("You have answered five questions")
            print("Well done")
            print("Let's see how many you got right")
            if Score == 500:
                print("")
                print("Well done you got all questions correct")
                print("You leveled up!")
                print("")
            elif Score <= 400:
                print("")
                print("Sorry but you got at least one question wrong")
                print("You need to start again")
                
                while QNum == 10:
                    Num1 = randint(1,10)
                    Num2 = randint(1,10)
                    QAns = Num1 + Num2
                    print("")
                    print("Q." + str(QNum))
                    ans = int(input("What is " + str(Num1) + " + " + str(Num2) + " " + "="))
                    P_Ans = str(input)
                    if ans == QAns:
                        print("Correct")
                        print("Well Done")
                        print("You earnt 100 points")
                        Score = Score + 100
                        QNum = QNum + 1
                    elif ans != QAns:
                        print("Incorrect")
                        print("Bad luck")
                        print("You earned 0 points")
                        Score = Score
                        QNum = QNum + 1
                    else:
                        print("")
                        print("You have answered five questions")
                        print("Well done")
                        print("Let's see how many you got right")
                        if Score == 500:
                            print("")
                            print("Well done you got all questions correct")
                            print("You leveled up!")
                        elif Score <= 400:
                            print("")
                            print("Sorry but you got at least one question wrong")
                            print("You need to start again")
                
main()
Any help is much appreciated!

Kind regards,
Some random year 8 student!

P.s. I like humor!
It would be helpful if you were to ask a specific question. For instance are you getting errors? If so you should paste the error code, in it's entirety (between the error tags). Are you getting an output different than what you expect? If so, at what point does this happen?

Your 'imports should be at the top of your code, not buried within it. I'm also not clear as to why you chose to put your all your code under the 'main()' function?

Anyway, I hope you can clarify the problem a bit more.