class Account:
"""一个模拟银行账户的简单类"""
def __init__(self, name, account_number, initial_amount = 10):
"""构造新账户"""
self._name = name
self._card_no = account_number
self._balance = initial_amount
def deposit(self, amount):
"""存款"""
self._balance += amount
def withdraw(self, amount):
"""取款"""
if self._balance < amount:
print('余额不足')
return
self._balance -= amount
def info(self):
"""打印账户信息"""
print('持卡人姓名:', self._name)
print('持卡人账号:', self._card_no)
print('持卡人账户余额:', self._balance)
def get_balance(self):
"""返回账户余额"""
return self._balance
def main():
"""创建Account类对象,测试类"""
print('测试账户1:'.center(30, '*'))
a1 = Account('Bob', '5002311', 20000)
a1.deposit(5000)
a1.withdraw(4000)
a1.info()
print()
print('测试账户2:'.center(30, '*'))
a2 = Account('Joe', '5006692', 20000)
a2.withdraw(10000)
a2.withdraw(5000)
a2.info()
if __name__ == '__main__':
main()
![]()
from shape import Rect, Circle
shape_lst = [Rect(5, 5, 10, 5), Circle(), Circle(1, 1, 10)]
for i in shape_lst:
i.info()
print(f'面积: {i.area(): .2f}')
print(f'周长: {i.perimeter(): .2f}')
print()
![]()
import math
def func(x, m, s):
a = (-1/2)*((x-m)/s)**2
y = math.exp(a)/(pow(2*math.pi, 0.5)*s)
print(f'x = {x},f = {y:.8f}')
x = [1, 3, 5, 7, 9]
for i in x:
func(i, 0, 2)
![]()