Пример #1
0
 def store(self, name, age, gpa, grade):
     student = Student()
     student.name = name
     student.age = age
     student.gpa = gpa
     student.grade = grade
     self.students.append(student)
Пример #2
0
 def store(self, name, age, gpa, grade):
     student = Student()
     student.name = name
     student.age = age
     student.gpa = gpa
     student.grade = grade
     self.students.append(student)
Пример #3
0
class TestStudent(unittest.TestCase):
    def setUp(self):
        self.student = Student(NAME, AGE)

    def test_name(self):
        self.assertEqual(self.student.name(), NAME)

    def test_age(self):
        self.assertEqual(self.student.age(), AGE)
Пример #4
0
#!/usr/bon/env python3
# -*- coding:utf-8 -*-

from fib import Fib
from student import Student

# __iter__
for n in Fib():
	print('n = ',n)

# __getitem__
f = Fib()
print('f[1] = ', f[1])

# slice
print('f[:5] = ',f[1:10])

# attr
s = Student()
age = s.age()
print(age)
# sex = s.sex()
# print(sex)

#call
dy = Student('Dylan')
dy()
Пример #5
0
from student import Student
from patient import Patient

John_Long = Student()
John_Long.first_name = "John"
John_Long.last_name = "Long"
John_Long.cohort = 36
John_Long.age = 46
# print(John_Long.age)
# print(John_Long.full_name)
print(John_Long)

pat1 = Patient("493-70-0000", "10/28/73", "7000111222", "John", "Long",
               "301 Plus Park Blvd")

pat1.address = "1638 County Rd 642"
print(pat1)
print(pat1.ssn, pat1.dob)
print(pat1.full_name)
Пример #6
0
from student import Student
from patient import Patient

sofia = Student()

sofia.first_name = "Sofia"
sofia.last_name = "Candiani"
sofia.age = 21
sofia.cohort = 38

print(sofia)

#patient

cashew = Patient("097-23-1003", "08/13/92", "7001294103", "Daniela",
                 "Agnoletti", "500 Infinity Way")

# This should not change the state of the object
# cashew.social_security_number = "838-31-2256"

# Neither should this
cashew.date_of_birth = "01-30-90"

# But printing either of them should work
print(cashew.social_security_number)  # "097-23-1003"

# These two statements should output nothing
# print(cashew.first_name)
# print(cashew.last_name)

# But this should output the full name
Пример #7
0
from student import Student
from group import Group

name = input('Please enter group name: ')
gr = Group(name)

cnt = int(input('Please enter count of studens: '))
for i in range(cnt):
    st = Student()
    st.name = input('Please enter name: ')
    st.age = int(input('Please enter age: '))
    cnt_g = int(input('Please enter count grades: '))
    for j in range(cnt_g):
        grade = int(input('Please enter grade {}: '.format(j + 1)))
        st.grades = grade

    gr.add_student(st)

print('Group:', gr.get_name())
for st in gr.get_students():
    print('Name:', st.name, '\tAge:', st.age, '\tGrades:',
          round(sum(st.grades) / len(st.grades), 2))

# def t(a, lst=None):
#     if not lst:
#         lst = []
#     lst.append(a)
#     print(lst)
#
#
# t(4)
Пример #8
0
def test_set_student_age():
	student = Student('Karlo',37)
	student.age = 38
	assert student.get_age_formatted == "38 years old"
Пример #9
0
from student import Student

if __name__ == '__main__':
    chulsu = Student('김철수', 24, '서울', '남성')
    print(chulsu)
    chulsu.city = '대전'  #setter
    chulsu.age = 34  #setter

    print(chulsu.name)  #getter
    print(chulsu.gender)  #getter
    print(chulsu)

    # jimin = Student('한지민', 22, '부산', '여성')
    # print(jimin)
Пример #10
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-  


#从student模块中导入Student类
from student import Student

s = Student('s1')
print s.name
#给Student动态绑定年龄属性
s.age  = 18
print s.age

#给Student动态绑定方法
def setAge(self,age):
	self.age = age
from types import MethodType
s.setAge = MethodType(setAge,s,Student)
s.setAge(19)
print s.age

#给一个实例动态绑定年龄和方法对别的实例没有影响
s2 = Student('s2')
# print s2.age

#为了给所有实例绑定方法 ,可以给class绑定方法
Student.setAge = MethodType(setAge,None,Student)
s2.setAge(20)
print s2.age
#为了给所有实例绑定属性,可以给class 绑定属性
Student.hello  = 'sssss'
from student import Student

# Testing:
alyssa = Student()
alyssa.first_name = "Alyssa"
alyssa.last_name = "Nycum"
alyssa.age = 30
alyssa.cohort_number = 38
# alyssa.first_name = 10
# print(alyssa.full_name)
# print(alyssa.first_name)
print(alyssa)

Пример #12
0
cursor = cnx.cursor()

query_for_students = ("select * from students")

query_for_courses = ("select * from course")

cursor.execute(query_for_students)

students = []

for student in cursor:
    s = Student(student[1], student[2], student[3])
    students.append(s)

cursor.execute(query_for_courses)

courses = []

for cc in cursor:
    c = Course(cc[1], cc[2])
    courses.append(c)

for s in students:
    print('Soyadı: %s | Adı: %s | Yaşı: %d' % (s.surname, s.name, s.age()))

for c in courses:
    print('Adı: %s | Adresi: %s' % (c.name, c.address))

cnx.cursor()
cnx.close()
Пример #13
0
from student import Student
from patient import Patient

new_student = Student()
new_student.first_name = "John"
new_student.last_name = "Doe"
new_student.cohort_number = 36
new_student.age = 42
# new_student.full_name = "Happy Days"
print(new_student)

cashew = Patient(
    "097-23-1003", "08/13/92", "7001294103",
    "Daniela", "Agnoletti", "500 Infinity Way")


# This should not change the state of the object
# cashew.social_security_number = "838-31-2256"

# Neither should this
# cashew.date_of_birth = "01-30-90"

# But printing either of them should work
print(cashew.social_security_number)
# "097-23-1003"

# # These two statements should output nothing
# print(cashew.first_name)
# print(cashew.last_name)

# # But this should output the full name