#Python Coding

18 messages · Page 1 of 1 (latest)

coarse pebble
#

do you know how to derive a class ? also what did you do so far ?

sullen bough
#

I have it loaded up at godbolt.org, how do i share this with you

coarse pebble
#

eh ...

#

can't you just copy the code ?

sullen bough
#

i guess this works?

coarse pebble
#

post it in a code block please 😄

#

t.tag code block

small spearBOT
#

To send code in discord follow this format:

```<lang>
your-code
```

Where <lang> is close-to any language you want.
Note, this ( ` ) is a forward tick, not a backward tick: ( ´ )

coarse pebble
#

so
```python
your-code
```

sullen bough
#

# Attributes: First, last name, ID
class User:#(object):
    def __init__(self, firstN, lastN, Boston_ID):  # Base class
        self.firstN = firstN      # Attributes are firstN, lastN, Boston_ID
        self.lastN = lastN
        self.Boston_ID = Boston_ID
    
    # Methods: Set function for each attribute, and a function to print all info for the object
    def first(self):
        print("First name:", self.firstN)
    def last(self):
        print("Last name:", self.lastN)
    def ID(self):
        print("ID: ", self.Boston_ID)
    def speak(self):
        print("Hi I am", self.firstN, self.lastN, "My ID is:", self.Boston_ID)


class Course:       # This class will have the ability to add students to a course
    def __init__(self, name, max_students):
        self.name = name
        self.max_students = max_students    # Max students that can be enrolled
        self.studnets = []                  # List of students that will be stored in "Couse"
    
    def add_student(self, student):         
        if len(self.studnets) < self.max_students:
            self.studnets.append(student)
            return True
        return False
    
    

S1 = User("Jimmy", "Vu.", 0o0000)
#S1.speak()
S2 = User("Linda", "Ross.", 0o0001)
#S2.speak()
S3 = User("Dave", "Habchi.", "W00002")
#S3.speak()

course = Course("Applied Programing Concepts", 2)       # "course" = name of function. "Course" = refrence to the class line20
course.add_student(S1)
course.add_student(S2)
print(course.name[])



# But what if I want 100 students?
Student_name = ["Jimmy Vu", "Linda Ross", "Dave Habchi"]
Studnet_ID = [0o001, 0o002, 0o003]
# This could work... but its a pain to find the index of the name and ID of each students

# Another way

coarse pebble
#

;compile ```py
lst1 = ["a", "b", "c"]
lst2 = [1, 2, 3]
for v1, v2 in zip(lst1, lst2):
print(v1, v2)

kindred hatchBOT
#
Program Output
a 1
b 2
c 3
coarse pebble
#

as for the other 3 classes

#

you derive them from the user class and add thier methods

#
class Student(User):
    def search_course(self, course):
        ...
    def add_course(self, course):
        ...
    ...
class Instructor(User):
    ...
sullen bough
#
class Student(User):
    def __init__(self, name, max_students):
        self.name = name
        self.max_students = max_students    # Max students that can be enrolled
        self.studnets = []                  # List of students that will be stored in "Couse"

    def search_course(self, course):        # Search
        self.course = course

    def add_course(self, add_course):       # Add
        self.add_course = add_course

    def drop_course(self, drop_course):     # Drop
        self.drop_course = drop_course

    def add_student(self, student):         # Students can add a course to their schedule but will have a max threshold.
        if len(self.studnets) < self.max_students:
            self.studnets.append(student)
            return True
        return False
    

class Instructor(User):
    def __init__(self, print, class_list, search):
        self.print = print
        self.class_list = class_list
        self.search = search