Python Forum
Increasing difficulty of a maths game
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Increasing difficulty of a maths game
#1
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!
Reply
#2
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.
If it ain't broke, I just haven't gotten to it yet.
OS: Windows 10, openSuse 42.3, freeBSD 11, Raspian "Stretch"
Python 3.6.5, IDE: PyCharm 2018 Community Edition
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Maths and python: Compute stress level cheerful 1 2,707 Oct-20-2021, 10:05 AM
Last Post: Larz60+
  Difficulty when trying to call all the input values extricate 2 1,928 Jun-05-2020, 09:36 AM
Last Post: pyzyx3qwerty
  4 tries choice question, one difficulty extricate 4 2,366 Jun-04-2020, 05:07 AM
Last Post: extricate
  why is there an unexpected maths result from a float calculation? maryab 3 2,847 Jun-09-2019, 08:28 PM
Last Post: snippsat
  Digits increasing meknowsnothing 6 4,062 Feb-17-2019, 11:22 AM
Last Post: scidam
  Writing python function difficulty kirito85 5 3,272 Oct-28-2018, 07:34 AM
Last Post: buran
  Making maths .py program faster Shutcois 1 2,566 Feb-16-2018, 06:39 PM
Last Post: nilamo
  Increasing depth in python malling 19 13,953 Oct-20-2016, 10:43 PM
Last Post: malling

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020