Kodomo

Пользователь

Учебная страница курса биоинформатики,
год поступления 2014

Title

   1 class Student:
   2     def __init__(self, name, uni, course):
   3         self.name = name
   4         self.uni = uni
   5         self.course = course
   6 st1 = Student("Vasya", "MSU", 2)
   7 st2 = Student("Petya", "PFU", 3)
   8 print(st1.name, st1.uni)
   9 print(st2.name, st2.uni)

   1 class Student:
   2     def __init__(self, name, uni, course):
   3         self.name = name
   4         self.uni = uni
   5         self.course = course
   6 
   7     def __str__(self):
   8         return("%s %s %i"%(self.name, self.uni, self.course))
   9 st1 = Student("Vasya", "MSU", 2)
  10 st2 = Student("Petya", "PFU", 3)
  11 print(st1)
  12 print(st2)
  13 print(st1)#<__main__.Student instance at 0x020749E0>

   1 class Student:
   2     def __init__(self, name, uni, course, coursera_courses={}):
   3         self.name = name
   4         self.uni = uni
   5         self.course = course
   6         self.c_courses = coursera_courses
   7 
   8     def __str__(self):
   9         return("%s %s %i"%(self.name, self.uni, self.course))
  10 
  11     def add_c_course(self, course_name, finished = False):
  12         self.c_courses[course_name] = finished
  13     def finish_c_course(self, course_name):
  14         self.c_courses[course_name] = True
  15     def get_finished_c_courses(self):
  16         return [x for x in self.c_courses.keys() if self.c_courses[x]]
  17 
  18 st1 = Student("Vasya", "MSU", 2, {"math":True, "biology":False, "informatics":False})
  19 print(st1)
  20 print(st1.c_courses)
  21 print(st1.get_finished_c_courses())
  22 st1.add_c_course("python")
  23 st1.add_c_course("R", True)
  24 print(st1.c_courses)
  25 print(st1.get_finished_c_courses())
  26 st1.finish_c_course("python")
  27 print(st1.c_courses)
  28 print(st1.get_finished_c_courses())

   1 import random
   2 import matplotlib.pyplot as plt
   3 
   4 x = [random.gauss(0,1) for i in range(200)]
   5 y = [random.gauss(0,1) for i in range(200)]
   6 col = ["b" if random.random()<0.5 else "r" for i in range(200)]
   7 plt.scatter(x, y, c=col, marker='^', s=25)
   8 plt.show()

   1 import random
   2 import matplotlib.pyplot as plt
   3 
   4 x = [random.gauss(0,1) for i in range(200)]
   5 y = [random.gauss(0,1) for i in range(200)]
   6 col = ["b" if random.random()<0.5 else "r" for i in range(200)]
   7 plt.scatter(x, y, c=col, marker='^', s=25)
   8 plt.title('Random points')
   9 plt.xlabel('random gauss x')
  10 plt.ylabel('random gauss x')
  11 x_min, x_max, y_min, y_max = 0, 3, -3, 0
  12 plt.axis( [x_min, x_max, y_min, y_max] )
  13 plt.show()

   1 import random
   2 import matplotlib.pyplot as plt
   3 
   4 x = [random.gauss(0,1) for i in range(200)]
   5 
   6 plt.hist(x, bins=20)
   7 plt.show()

   1 import matplotlib.pyplot as plt
   2 x=[0.1,0.2,0.4,0.5,0.7]
   3 y1=[1,4,9,2,6]
   4 y2=[2,3,8,2,5]
   5 
   6 plt.plot(x,y1,'b-')
   7 plt.plot(x,y2,'r-')
   8 
   9 plt.show()

Наследование