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

2020-10-12  本文已影响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)
上一篇 下一篇

猜你喜欢

热点阅读