week7

作者: 猪蹄炖粥 | 来源:发表于2018-08-04 23:46 被阅读4次

视频总结

final exam :
报错:
'int' object is not callable,此参数已被声明为int,不可作为函数调用
stackoverflow:https://stackoverflow.com/questions/9767391/typeerror-int-object-is-not-callable
原因:调用函数时传参了int类型,实际上应该参数定义是函数,之后的函数调用就会报此错误

python中的self

  • __init__函数默认的第一个参数
  • 类中方法的第一参数永远是类的本身实例变量self,并且调用时,不用传递

第二题答案

# Paste your entire definition of the edx class in this box
class edx(object):
    # edc类
    def __init__(self, courses):
        # 初始化 我的课程
        # 用一个数组初始化
        self.myCourses = []
        for course in courses:
            self.myCourses.append(courseInfo(course))

    def setGrade(self, grade, course="6.01x"):
        """
        grade: integer greater than or equal to 0 and less than or equal to 100
        course: string 

        This method sets the grade in the courseInfo object named by `course`.   

        If `course` was not part of the initialization, then no grade is set, and no
        error is thrown.

        The method does not return a value.
        """
        #   fill in code to set the grade
        for index in range(len(self.myCourses)):
            if(self.myCourses[index].courseName == course):
                self.myCourses[index].setGrade(grade)

    def getGrade(self, course="6.02x"):
        """
        course: string 

        This method gets the grade in the the courseInfo object named by `course`.

        returns: the integer grade for `course`.  
        If `course` was not part of the initialization, returns -1.
        """
        #   fill in code to get the grade
        for index in range(len(self.myCourses)):
            if(self.myCourses[index].courseName == course):
               return self.myCourses[index].getGrade()

    def setPset(self, pset, score, course="6.00x"):
        """
        pset: a string or a number
        score: an integer between 0 and 100
        course: string

        The `score` of the specified `pset` is set for the
        given `course` using the courseInfo object.

        If `course` is not part of the initialization, then no pset score is set,
        and no error is thrown.
        """
        #   fill in code to set the pset
        for index in range(len(self.myCourses)):
            if(self.myCourses[index].courseName == course):
                self.myCourses[index].setPset(pset,score)
               


    def getPset(self, pset, course="6.00x"):
        """
        pset: a string or a number
        course: string        

        returns: The score of the specified `pset` of the given
        `course` using the courseInfo object.
        If `course` was not part of the initialization, returns -1.
        """
        #   fill in code to get the pset
        for index in range(len(self.myCourses)):
            if(self.myCourses[index].courseName == course):
                self.myCourses[index].getPset(pset)

chp 11

PyLab类似matlab绘图,练习绘图,完整代码如下:

import pylab
class Mortgage(object):
    """建立不同种类抵押贷款的抽象类"""
def __init__(self, loan, annRate, months):
    self.loan = loan
    self.rate = annRate/12.0
    self.months = months
    self.paid = [0.0]
    self.outstanding = [loan]
    self.payment = findPayment(loan, self.rate, months)
    self.legend = None #description of mortgage
def makePayment(self):
    self.paid.append(self.payment)
    reduction = self.payment - self.outstanding[-1]*self.rate
    self.outstanding.append(self.outstanding[-1] - reduction)
def getTotalPaid(self):
    return sum(self.paid)
def __str__(self):
    return self.legend
def plotPayments(self, style):
    pylab.plot(self.paid[1:], style, label = self.legend)
def plotBalance(self, style):
    pylab.plot(self.outstanding, style, label = self.legend)
def plotTotPd(self, style):
    totPd = [self.paid[0]]
    for i in range(1, len(self.paid)):
        totPd.append(totPd[-1] + self.paid[i])
    pylab.plot(totPd, style, label = self.legend)

def plotNet(self, style):
    totPd = [self.paid[0]]
    for i in range(1, len(self.paid)):
        totPd.append(totPd[-1] + self.paid[i])
    equityAcquired = pylab.array([self.loan] * len(self.outstanding))
    equityAcquired = equityAcquired - pylab.array(self.outstanding)
    net = pylab.array(totPd) – equityAcquired
    pylab.plot(net, style, label = self.legend)

相关文章

  • JK计划训练日记

    Week7 Day 6 June 23 Strict pull up 3 unbroken sets x 12 r...

  • CS229 Week7 SVM

    title: CS229 Week7 SVMdate: 2017-03-26 18:44:02categories...

  • 麻袋产品汪 APT W7:后台产品逻辑|竞品分析入门|微信小程序

    发布日期:2016-09-24 编辑:朱老湿 版本:Week7 说明:APT=Awesome product to...

  • week7

    视频总结 final exam :报错:'int' object is not callable,此参数已被声明为...

  • Week7

    本周目标 完成同时使用生成的配置文件以及读取原来DB中的配置文件,并且根据同一个domain object的改动生...

  • week7

    工作: 过完年的第一周就很忙,因为别的国家没有放假。 接手过来的项目,有很多吐槽的地方。比如流程上可以在生产环境随...

  • TED的一些重新设计和思考

    Weekly redesign challenge Week7 这周实在是不知道该做什么app的redesign了...

  • 2020年Week7 复盘

    Week7 2020.2.10~2020.2.16 冲刺上传产品中这周计划所有的时间都是在上传产品,已经上传完...

  • 21年Week07|春节周:爱与被爱,比较与被比较....

    Week7 8.2.2021—14.2.2021 第07周关键词:春节周、闲散、玩玩玩 回顾 Week07 五种时...

  • 2018-08-24

    学习安排(8月21日-8月23日)1.主要学习视频Week7链接(http://www.xuetangx.com/...

网友评论

      本文标题:week7

      本文链接:https://www.haomeiwen.com/subject/qoevvftx.html