首页 > 其他分享 >实验七

实验七

时间:2023-06-14 09:26:00浏览次数:34  
标签:self 8f amount 实验 func ._ print

task1

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():
    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()

截图

 task2

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()

截图

 task3

from math import *
m = 0
s = 2
def func(x):
    return 1/(sqrt(2*pi)*s)*(exp((-0.5)*((x-m)/s)**2))



print(f'x = 1,f = {func(1):.8f}')
print(f'x = 3,f = {func(3):.8f}')
print(f'x = 5,f = {func(5):.8f}')
print(f'x = 7,f = {func(7):.8f}')
print(f'x = 9,f = {func(9):.8f}')

截图

 

标签:self,8f,amount,实验,func,._,print
From: https://www.cnblogs.com/melancholy-z/p/17479218.html

相关文章

  • 实验7 面向对象编程与内置模块
    实验任务1task1.py1classAccount:23def__init__(self,name,account_number,initial_amount=10):4self._name=name5self._card_no=account_number6self._balance=initial_amount7defdeposit(self,amount):......
  • 实验7 面向对象编程与内置模块
    task1源代码'''银行账户数据:持卡人姓名、账号、当前余额操作:取款、存款、打印账户信息、返回账户余额'''classAccount:'''一个模拟银行账户的简单类'''def__init__(self,name,account_number,initial_amount=10):''......
  • 实验7 面向对象编程与内置模块
    实验任务1task1.py1classAccount:23def__init__(self,name,account_number,initial_amount=10):4self._name=name5self._card_no=account_number6self._balance=initial_amount7defdeposit(self,amount):......
  • 实验7 面向对象编程与内置模块
    task1源代码:classAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,amount):self._balance+=amount......
  • Kong入门学习实践(2)实验环境搭建
    最近在学习Kong网关,因此根据老习惯,我会将我的学习过程记录下来,一来体系化整理,二来作为笔记供将来翻看。由于我司会直接使用Kong企业版,学习过程中我会使用Kong开源版。本篇,我们学习如何快速搭建一个Kong实验环境。搭建方式目前,我们可以选择多种部署方式,包括:宿主机部署、Docker部......
  • 实验7
    task1'''银行账户数据:持卡人姓名、账号、当前余额操作:取款、存款、打印账户信息、返回账户余额'''classAccount:'''一个模拟银行账户的简单类'''def__init__(self,name,account_number,initial_amount=10):'''构造新账......
  • 实验七
    实验任务一实验源码:classAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,amount):'''存款'&#......
  • 实验7 面向对象编程与内置模块
    task1'''银行账户数据:持卡人姓名、账号、当前余额操作:取款、存款、打印账户信息、返回账户余额'''classAccount:'''一个模拟银行账户的简单类'''def__init__(self,name,account_number,initial_amount=10):'''构造新......
  • 实验七
    task11classAccount:2def__init__(self,name,account_number,initial_amount=10):3self._name=name4self._card_no=account_number5self._balance=initial_amount67defdeposit(self,amount):8self._bala......
  • 实验七
    实验任务一task1源代码:'''银行账户数据:持卡人姓名、账号、当前余额操作:取款、存款、打印账户信息、返回账户余额'''classAccount:'''一个模拟银行账户的简单类'''def__init__(self,name,account_number,initial_amount=10):'......