美文网首页
《Python 程序设计》课程作业参考答案 2020~2021-

《Python 程序设计》课程作业参考答案 2020~2021-

作者: 麥丹慈 | 来源:发表于2020-10-12 16:55 被阅读0次

第三次

import math


def area_circle(r): return math.pi * r ** 2


def main():
    r = float(input(
        r'Please enter a radius of the circle that you want to calculate its area: '))
    assert r > 0, r'Radius should be larger than zero.'
    print(r'The area of the circle is ', area_circle(r), r'.', sep=r'')


main()

第四次

class Card(object):
    pass


class IC(Card):
    pass


class CampusCard(IC):
    def __init__(self, id=None):
        if id == None:
            id = 0
        self.__id = id
        self.__balance = 0

    @property
    def id(self):
        return self.__id

    def __repr__(self):
        return str(self.__id).rjust(7, r'0')

    def charge(self, amount):
        self.__balance += amount

    def comsume(self, amount):
        self.__balance -= amount

    def report_of_loss(self):
        print(r'Loss', self.__id, self.__balance)

相关文章

网友评论

      本文标题:《Python 程序设计》课程作业参考答案 2020~2021-

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