计算收益
p = int(input(‘请输入你的本金:’))
r = int(input(‘请输入利率:’))
n = int(input(‘请输入存的年份:’))
amount = p+p*(1+r)**n
print(‘本金利率和是:{:.2f}’.format(amount))
1
2
3
4
5
6
计算球体的表面积和体积
import math
r = int(input(‘请输入球的半径:’))
area = 4math.pir2
volume = 4/3math.pir3
print(‘球的表面积是:{:.2f},球的体积是:{:.2f}’.format(area,volume))
1
2
3
4
5
6
7
申明函数计算收益
ef getvalue(b,r,n):
v = b*(1+r)**n
return v #这里一定要返回值,不然amount就会不被定义
b = int(input(‘请输入本金:’))
r = int(input(‘请输入利率:’))
n = int(input(‘请输入年份:’))
amount = getvalue(b,r,n)
print(‘最终收益:{:.2f}’.format(amount))
1
2
3
4
5
6
7
8
9
10
计算函数x*x-10x+16=0的解
import math
a = float(input(‘请输入a:’))
b = float(input(‘请输入b:’))
c = float(input(‘请输入c:’))
d = b**2-4ac
if a != 0:
if d < 0:
print(‘无解’)
elif d == 0:
s = -b/(2a)
print(‘唯一根:x=’,s)
else:
s1 = (-b-math.sqrt(d))/(2a)
s2 = (-b+math.sqrt(d))/(2*a)
print(‘两解,x1={:.2f},x2={:.2f}’.format(s1,s2))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
计算您今年多少岁
import datetime
n = input(‘请输入你的姓名:’)
y = int(input(‘请输入你的出生年月:’))
w = datetime.date.today().year
print(‘您好!{}。您{}岁’.format(n,w-y))