Creating objects in a loop in Python [duplicate]

This question already has an answer here:

this is my first post so I am sorry if I get any formatting wrong.

I have searched this before in stackoverflow and it did come up with a few responses but I didn’t really understand as I couldn’t relate to the code. I am trying to practise object oriented programming and what I am trying to do is I have a Student class and I have a menu that I want to loop as long as the user does not input -1. Right now when the user presses 1, I want a new object to be created, but every time that the menu loop loops, I want a new object to be made. What I am thinking could work is adding a counter for a while loop for the mainfunction, and everytime the user inputs “1”, the counter adds 1. THen when creating the object it could look is: student = Studentcounter. I am not really sure and I am sorry if there are many other posts like this but I am a newbie haha.

class Student:
#name = ""      Do i need to put there variables here?
#age = 0
#science = 0
#maths = 0
#english = 0
def __init__(self,name,age,science,maths,english): = name
    self.age = age = science
    self.maths = maths
    self.english = english

def mainFunct():
dictStudent = {}
mainBool = True
while mainBool == True:
    print("WElcome to rafs student grade book a")
    #while True:
    menu = int(input("1) view students in specific class 2) Delete Student 3) Highest to lowest grades 4) Change student to a new class 5) add new marks 6) Change"))
        #except ValueError:
                  #print("Please enter in a number")

    if menu == 1:
        name = input("What is their name")
        age = input("What is their age")
    while True:
        science = int(input("What was their science result out of 100"))
        if science <= 100:
    while True:
        maths = int(input("What was their maths result out of 100"))
        if maths <= 100:
    while True:
        english = int(input("What was their english result out of 100"))
        if english <= 100:
    student = Student(name,age,science,maths,english)


Source: oop

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.