首页 > 其他分享 >实验7

实验7

时间:2023-06-13 10:45:57浏览次数:31  
标签:self amount 实验 ._ print balance def

任务1

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

任务2

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

任务3

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

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,amount,实验,._,print,balance,def
From: https://www.cnblogs.com/chaomifeng/p/17476838.html

相关文章

  • 实验7
    task4编程代码#include<stdio.h>#include<stdlib.h>intmain(){FILE*fp;intx=0;charch;if((fp=fopen("d:\\data4.txt","r"))==NULL){printf("Failtoinitialize\n");e......
  • 实验七
    TASK4#include<stdio.h>intmain(){charch;intcount=0;FILE*fp;fp=fopen("D:\data4.txt","r");if(fp==NULL){printf("failtoopenfile\n");......
  • 实验7
    task1.py1classAccount:2'''一个模拟银行账户的简单类'''3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._ca......
  • 实验7
    task1_1#include<stdio.h>#defineN7#defineM80typedefstruct{charname[M];charauthor[M];}Book;intmain(){Bookx[N]={{"《雕塑家》","斯科特·麦克劳德"},{"《灯塔》","克里斯多夫·夏布特"},......
  • 实验7
    实验任务1实验源码1classAccount:2def__init__(self,name,account_number,initial_amount=10):3self._name=name4self._card_no=account_number5self._balance=initial_amount6defdeposit(self,amount):7......
  • 实验7 面向对象编程与内置模块
    task1程序源码:1'''2银行账户3数据:持卡人姓名、账号、当前余额4操作:取款、存款、打印账户信息、返回账户余额5'''6classAccount:7'''一个模拟银行账户的简单类'''89def__init__(self,name,account_number,initial_amount=1......
  • 实验7 面向对象编程与内置模块
    task1实验源码:1#12classAccount:3def__init__(self,name,account_number,initial_amount=10):4self._name=name5self._card_no=account_number6self._balance=initial_amount78defdeposit(self,amount):9......
  • 实验7 面向对象编程与内置模块
    实验任务1task1.py程序源码:1'''2银行账户3数据:持卡人姓名、账号、当前余额4操作:取款、存款、打印账户信息、返回账户余额5'''67classAccount:8'''一个模拟银行账户的简单类'''9def__init__(self,name,account_number,initial_a......
  • 实验7
    task1.py实验源码:1classAccount:2#一个模拟账户类3def__init__(self,name,account_number,initial_amount=10):4'''构造新账户'''5self._name=name6self._card_no=account_number7sel......
  • CJJC项目实验环境配置
    CJJC项目实验环境配置 (base)D:\>(base)D:\>condacreate-nwind_2022python==3.7Solvingenvironment:done##PackagePlan##environmentlocation:D:\Anaconda3\envs\wind_2022added/updatedspecs:-python==3.7Thefollowingpackages......