#1输入摄氏度转化为华氏度
cel = float(input("请输入摄氏度:"))
f = (9 / 5) * cel + 32
print("对应的华氏度:"+ str(f))
#2计算圆柱体的底面积和体积
radius = float(input("请输入圆柱体的半径"))
length = float(input("请输入圆柱体的高"))
area = radius * radius * 3.14
volume = area * length
print("对应的底面积:" + str(area))
print("对应的体积:" + str(length))
#3对一个整数中各位数字求和
a = float(input("请输入0~1000的整数"))
b = a//100
c = a//10%10
d = a % 10
e = b + c + d
print("各位数字之和:%s"%(e))
#4计算年数和天数
min = int(input("请输入一个分钟数:"))
year = min // (365 * 24 * 60)
min1 = min % (365 * 24 * 60)
day = min1//(24 * 60)
print("%s分钟数是%s年%s天"%(min,year,day))
#5计算能量
M = float(input("请输入千克计算的水量:"))
initialTemperature = float(input("请输入水的初始温度:"))
finalTemprature = float(input("请输入水的最终温度:"))
Q = M * (finalTemprature - initialTemperature) * 4184
print("所需要的能量:" + str(Q))
#6风寒温度
ta = float(input("请输入-58~41之间的温度:"))
v = float(input("请输入每小时2里以上的风速:"))
tw = 35.74 + 0.6215 * ta - 35.75 * (b ** 0.16) + 0.4275 * ta *(C ** 0.16)
print("风寒温度:" + str(tw))
#7计算跑道的长度
(v,a) = eval(input("请输入速度和加速度: "))
length = (v ** 2) / (2 * a)
print("最短跑道长度:" + str(length))
#8分割数字
number = int(input("请输入一个四位整数:"))
num1 = number % 10 #个位
num2 = number // 10 #十位百位千位
num3 = num2 % 10 #十位
num4 = num2 // 10 #百位千位
num5 = num4 % 10 #百位
num6 = num4//10 #千位
print("%d\n%d\n%d\n%d"%(num1,num3,num5,num6))
或者:
number = (input("请输入一个四位整数:"))
print(number[::-1]) #切片
#9几何方面:三角形的面积
(x1,y1,x2,y2,x3,y3) = eval(input("请输入三角形的三个顶点:"))
s1 = ((x1 - x2) ** 2+(y1 - y2) ** 2) ** (1/2)
s2 = ((x1 - x3) ** 2+(y1 - y3) ** 2) ** (1/2)
s3 = ((x2 - x3) ** 2+(y2 - y3) ** 2) ** (1/2)
s = (s1 + s2 + s3)/2
area = (s * (s - s1) * (s - s2) * (s - s3))**(1/2)
print("三角形的面积:" + str(area))
或者:
import math
(x1,y1,x2,y2,x3,y3) = eval(input("请依次输入点的坐标:"))
side1 = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
side2 = math.sqrt((x1 - x3)**2 + (y1 - y3)**2)
side3 = math.sqrt((x2 - x3)**2 + (y2 - y3)**2)
s = (side1 + side2 + side3)/2
area = math.sqrt(s * ((s - side1) * (s - side2) * (s - side3)))
print("三角形的面积:" + str(area))
#10正六边形的面积
s = float(input("请输入正六边形的边长:"))
S = ((3 * (3**(1/2)))/2) * (s**2)
print("正六边形的面积:" + str(S))
#11当前时间
#12复利值
money = float(input("请输入每月存储的金额:"))
money1 = money * (1 + 0.00417)
money2 = (money + money1)* (1 + 0.00417)
money3 = (money + money2)* (1 + 0.00417)
money4 = (money + money3)* (1 + 0.00417)
money5 = (money + money4)* (1 + 0.00417)
money6 = (money + money5)* (1 + 0.00417)
print("六个月后的账户总额:"+str(money6))
#13计算未来投资额
Money = float(input("投资额:"))
rate = float(input("年利率:"))
year = float(input("投资年数:"))
Money1 = Money * (1 + rate / 12)**(year / 12)
print("未来投资额:" + str(Money1))
#14计算三角形的三个角
a = float(input("请输入a边的长度:"))
b = float(input("请输入b边的长度:"))
c = float(input("请输入c边的长度:"))
cosA = (b**2 + c**2 - a**2)/(2 * b * c)
cosB = (a**2 + c**2 - b**2)/(2 * a * c)
cosC = (a**2 + b**2 - c**2)/(2 * a * b)
print("ABC三边的余弦值分别为:%s %s %s"%(cosA,cosB,cosC))
#15一个正多边形的面积
import math
n = float(input("请输入多边形的边数:"))
s = float(input("请输入多边形的边长:"))
Area = (n*(s**2))/(4*math.tan(3.14/n))
print("面积:"+ str(Area))
#16反向数字
#17货币转换
U = float(input("请输入一个十进制带小数的数字:"))
fenshu = U * 100
meiyuangeshu = fenshu // 100
shengyufenshu = fenshu % 100
liangjiaowufen = shengyufenshu // 25
youshengyufenshu = shengyufenshu % 25
yijiaoyingbi = youshengyufenshu // 10
haishengyufenshu = youshengyufenshu % 10
wufenyingbi = haishengyufenshu // 5
zaicishengyufenshu = haishengyufenshu % 5
print("美元个数:"+ str(meiyuangeshu))
print("两角五分个数:"+ str(liangjiaowufen))
print("一角硬币个数:"+ str(yijiaoyingbi))
print("五分硬币个数:"+ str(wufenyingbi))
print("一美分分硬币个数:"+ str(zaicishengyufenshu))
#18工资表
name = (input("请输入雇员姓名:"))
time = float(input("请输入一周工作时间:"))
money = float(input("请输入每小时报酬:"))
L = float(input("请输入联邦预扣税率:"))
LL = float(input("请输入州预扣税率:"))
s = money * time
d = s * L
D = s * LL
h = d + D
H = s - h
print("雇员姓名:"+ str(name))
print("一周工作时间:"+str(time))
print("每小时报酬:" + str(money))
print("未扣税工资:"+ str(s))
print("联邦预扣税(20.0%):"+ str(d))
print("州预扣税(9.0%)):"+ str(D))
print("总扣工资:"+ str(h))
print("剩余工资:"+ str(H))