首页 > 其他分享 >实验七

实验七

时间:2023-06-13 22:23:13浏览次数:26  
标签:10 self amount 实验 ._ print def

task1

 1 class Account:
 2     def __init__(self,name,account_number,initial_amount=10):
 3         self._name=name
 4         self._card_no=account_number
 5         self._balance=initial_amount
 6 
 7     def deposit(self,amount):
 8         self._balance+=amount
 9 
10     def withdraw(self,amount):
11         if self._balance<amount:
12             print('余额不足')
13             return
14 
15         self._balance-=amount
16 
17     def info(self):
18         print('持卡人姓名:',self._name)
19         print('持卡人账号:',self._card_no)
20         print('持卡人账户余额:',self._balance)
21 
22     def get_balance(self):
23         return self._balance
24 
25 def main():
26     print('测试账户1:'.center(30,'*'))
27     a1=Account('Bob','5002311',20000)
28     a1.deposit(5000)
29     a1.withdraw(4000)
30     a1.info()
31 
32     print()
33 
34     print('测试账户2:'.center(30,'*'))
35     a2=Account('Joe','5006692',20000)
36     a2.withdraw(10000)
37     a2.withdraw(5000)
38     a2.info()
39 
40 if __name__=='__main__':
41     main()

task2

1 from shape import Rect, Circle
2 shape_lst = [Rect(5, 5, 10, 5), Circle(), Circle(1, 1, 10)]
3 for i in shape_lst:
4     i.info()
5     print(f'面积: {i.area(): .2f}')
6     print(f'周长: {i.perimeter(): .2f}')
7     print()

task3:

1 from math import*
2 def func(x):
3     a=-(x/2)**2/2
4     ans=exp(a)/(2*pi)**0.5/2
5     return ans
6 
7 for i in range(1,10,2):
8     print(f'x={i},f={func(i):.8f}')

task4

 

标签:10,self,amount,实验,._,print,def
From: https://www.cnblogs.com/-bug/p/17478853.html

相关文章

  • 实验七
    实验任务一task1源代码:'''银行账户数据:持卡人姓名、账号、当前余额操作:取款、存款、打印账户信息、返回账户余额'''classAccount:'''一个模拟银行账户的简单类'''def__init__(self,name,account_number,initial_amount=10):'......
  • 实验 7
    1classAccount:2def__init__(self,name,account_number,initial_amount=10):3self._name=name4self._card_no=account_number5self._balance=initial_amount6defdeposit(self,amount):7self._b......
  • 浪潮信息获颁泰尔实验室首张服务器碳足迹证书
    日前,权威检测机构中国泰尔实验室颁发首张服务器产品碳足迹认证证书。经过对原材料获取、整机生产、运输、包装、产品使用到产品拆解回收等全生命周期的评估测试,每万台浪潮信息NF5280M6全生命周期较业界平均水平可节约碳排放686吨,相当于植树5万棵,达到业内领先水平。*泰尔实验室作为......
  • 实验七 面向对象编程与内置模块
    实验任务1task1.pyclassAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,amount):self._balance+=amoun......
  • 实验7
    TEST4#include<stdio.h>#include<stdlib.h>intmain(){intnum=0;charch;FILE*fp;fp=fopen("data4.txt","r");if(fp==NULL){printf("fail\n");return1;}while(!feof(fp))......
  • 实验七
    classAccount:def__init__(self,name,account_number,initial_amount=10):self._name=nameself._card_no=account_numberself._balance=initial_amountdefdeposit(self,amount):self._balance+=amountdefwithd......
  • c语言:计数器实验
    要求:P1口接2只LED灯,定时器T1采用计数模式,方式1中断,外接按钮开关作为计数输入,当按2次按钮开关,P1口第一只LED点亮,再按2次按钮开关,P1口第二只LED点亮,再按2次按钮,所有LED灯熄灭。 1#include<reg52.h>23//定义LED灯的控制端口和对应的控制位4sbitLED1=P1^0;5......
  • 实验7
    任务4程序源码:#define_CRT_SECURE_NO_WARNINGS#include<stdio.h>intmain(){charch;FILE*fp;inti=0;fp=fopen("data4.txt","r");ch=fgetc(fp);while(ch!=EOF){if(ch!=''&......
  • 实验七
    task11classAccount:2def__init__(self,name,account_number,initial_amount=10):3self._name=name4self._card_no=account_number5self._balance=initial_amount67defdeposit(self,amount):8self.......
  • 实验7
    task3importmathdeffunc(x):f=((math.e)**((-0.5)*(((x-m)/s)**2)))/(s*math.sqrt(2*(math.pi)))returnf'{f:.8f}'m=0s=2x_lst=[1,3,5,7,9]forxinx_lst:print(f'x={x},f={func(x)}') ......