jeudi 28 novembre 2019

How can I make my main program appear first and how can I call my functions in my main program?

Right now I've tried making my main program the main "function" in my code. But when I run it, the analysis bit comes up first which is not what i want. I want to make my code to do the following: output the main program so the user can input the marks total and input the marks scored in a test.

"Write a program that inputs a mark from the keyboard for sections of a project: ‘analysis’, ‘design’, ‘implementation’ and ‘evaluation’. The program should output the total mark, the grade, and how many more marks were needed to get into the next mark band."

That was my task.


    def analysis():
        print("Welcome to the analysis section")
        marktotal=int(input("Input mark total which is out of /100"))
        marks=int(input("Input marks"))
        totalanalysis=print("You got",marks,"/",marktotal)
        if marks > 80 or marks == 80:
            print("A*")
        elif marks > 67 or marks == 67:
            print("A")
        elif marks > 54 or marks == 54:
            print("B")
        elif marks > 41 or marks == 41:
            print("C")
        elif marks > 31 or marks == 31:
            print("D")
        elif marks > 22 or marks == 22:
            print("E")
        elif marks > 13 or marks == 13:
            print("F")
        elif marks > 4 or marks == 4:
            print("G")
        elif marks ==0:
            print("U")
        return
    analysis()

    def design():
        print("Welcome to the design section")
        marktotal=int(input("Input mark total which is out of /100"))
        marks=int(input("Input marks"))
        totalanalysis=print("You got",marks,"/",marktotal)
        return

    design()


    def main():
        selectedsection=str(input("What section would you like to grade?"))#main program starts here
        if selectedsection =="analysis":
                analysis()
        elif selectedsection =="design":
                print("design")
        elif selectedsection =="implementation":
                 print("implementation")
        elif selectedsection =="evaluation":
                print("evaluation")

    if __name__ == "__main__":main()
    ```

Aucun commentaire:

Enregistrer un commentaire