第五次上机题目 Problem 1 问题描述: 在l0.3.2中的projectile..py程序基础上,添加getDistance(self,time)函数,计算质点在time 时间内运行的路程。 程序文件命名:1py Problem 2 问题描述:第十章课后第l7题:首先定义Regression类,然后使用Regression类,完成第 8章的Programming Exercise 13的要求。 Redo the regression problem from Chapter8(Programming Exercise 13)using a Regression class. Your new class will keep track of the various quantities that are needed to compute a line of regression(the running sums of x,y,x2,and xy).The regression class should have the following methods: init Creates a new regression object to which points can be added. addPoint Adds a point to the regression object. predict Accepts a value of x as a parameter,and returns the value of the corresponding y on the line of best fit. Note:Your class might also use some internal helper methods to do such things as compute the slope of the regression line. 程序文件命名:2py Problem 3 问题描述:Chapter1 1 Exercises 19 Create and test a Set class to represent a classical set.Your sets should support the following methods: Set(elements)Create a set(elements is the initial list of items in the set). addElement (x)Adds x to the set. deleteElement(x)Removes x from the set,if present.If x is not in the set,the set is left unchanged
第五次上机题目 Problem 1 问题描述: 在 10.3.2 中的 projectile.py 程序基础上,添加 getDistance(self,time)函数,计算质点在 time 时间内运行的路程。 程序文件命名:1.py Problem 2 问题描述:第十章课后第 17 题:首先定义 Regression 类,然后使用 Regression 类,完成第 8 章的 Programming Exercise 13 的要求。 Redo the regression problem from Chapter 8 (Programming Exercise 13) using a Regression class. Your new class will keep track of the various quantities that are needed to compute a line of regression (the running sums of x, y, x 2 , and xy). The regression class should have the following methods: __init__ Creates a new regression object to which points can be added. addPoint Adds a point to the regression object. predict Accepts a value of x as a parameter, and returns the value of the corresponding y on the line of best fit. Note: Your class might also use some internal helper methods to do such things as compute the slope of the regression line. 程序文件命名:2.py Problem 3 问题描述:Chapter 11 Exercises 19 Create and test a Set class to represent a classical set. Your sets should support the following methods: Set (elements) Create a set (elements is the initial list of items in the set). addElement (x) Adds x to the set. deleteElement(x) Removes x from the set, if present. If x is not in the set, the set is left unchanged
member (x)Returns true if x is in the set and false otherwise. intersection(set2)Returns a new set containing just those elements that are common to this set and set2. union(set2)Returns a new set containing all of elements that are in this set,set2,or both display()Show all the elements in the set Use the following program to test your new class. def main(): 1st1=[1,2,3,4,5,6] 1st2=[5,6,7,8,9] s1=Set(Ist1) s2=Set(Ist2) s1.addElement(8) s2.deleteElement(10) s3=s1.intersection(s2) s4=s1.union(s2) s3.display() s4.display() 程序文件命名:3py
member (x) Returns true if x is in the set and false otherwise. intersection(set2) Returns a new set containing just those elements that are common to this set and set2. union (set2) Returns a new set containing all of elements that are in this set, set2, or both. display() Show all the elements in the set Use the following program to test your new class. def main(): lst1=[1,2,3,4,5,6] lst2=[5,6,7,8,9] s1=Set(lst1) s2=Set(lst2) s1.addElement(8) s2. deleteElement(10) s3=s1. intersection(s2) s4=s1.union(s2) s3.display() s4.display() 程序文件命名:3.py