1.
代码:
1.
Celsius = int(input("Enter a degree in Celsius:"))
f = (9/5) * Celsius + 32
print("%s Celsius is %s Fahrenheit"%(Celsius,f))
运行结果:
2.
代码:
radius = float(input("radius:"))
length = int(input("length:"))
p = 3.1415926
area = (radius**2)*p
print("area:",area)
print("volume:",(area * length))
运行结果:
3.
代码:
num = int(input("输入一个0到1000之间的整数:"))
num_first = num%10
num_second = (num//10)%10
num_third = num//100
print("sum=",(num_first+num_second+num_third))
运行结果:
4.
代码:
minutes = int(input("请输入分钟数:"))
yaer = minutes//525600
day = ((minutes/525600)-(minutes//525600))*365//1
print("day为%s,yaer为%s"%(day,yaer))
运行结果:
5.
代码:
water = float(input("水重量(kg):"))
water_initial = float(input("初始温度:"))
water_final = float(input("最终温度:"))
Q = water * (water_final - water_initial) * 4184
print("该重量下水从初始温度加热到最终温度所需要的能量为:"+str(Q))
运行结果:
6.
代码:
tep = float(input("请输入一个-58华氏度到41华氏度之间的温度:"))
if tep>41 or tep<-58:
print(tep1 = float(input("请重新输入一个-58华氏度到41华氏度之间的温度:")))
sp = int(input("请输入一个大于等于每小时2里的风速:"))
Twc = 35.74 + 0.6215*tep -35.75*(sp**0.16) + 0.4275*tep*(sp**0.16)
print("风寒温度为:"+str(Twc))
运行结果:
7.
代码:
sp,a = eval(input("起飞速度和加速度为:"))
l = (sp**2)/(2*a)
print("最短的跑道长度为:",l)
运行结果:
8.
代码:
num = int(input("输入四位整数:"))
num_first = num//1000
num_second = (num %1000)//100
num_third = (num%100)//10
num_fourth = num%10
print(num_fourth)
print(num_third)
print(num_second)
print(num_first)
运行结果:
9.
代码:
import math
x1 = float(input("请输入x1的坐标:"))
y1 = float(input("请输入y1的坐标:"))
x2 = float(input("请输入x2的坐标:"))
y2 = float(input("请输入y2的坐标:"))
x3 = float(input("请输入x3的坐标:"))
y3 = float(input("请输入y3的坐标:"))
s1 = math.sqrt(((x1-x2)**2)+((y1-y2)**2))
s2 = math.sqrt(((x1-x3)**2)+((y1-y3)**2))
s3 = math.sqrt(((x2-x3)**2)+((y2-y3)**2))
s = (s1+s2+s3)/2
area = math.sqrt(s*((s-s1)*(s-s2)*(s-s3)))
print("面积为:"+str(area))
运行结果:
10.
代码:
import math
side = float(input("这个正六边形边长:"))
area = (3*(math.sqrt(3))*(side**2))/2
print("面积为:",area)
运行结果:
11不做
12.
代码:
dollar = int(input("每一个月存:"))
month_1 = dollar*(1+0.00417)
month_2 = (month_1 + dollar)*(1+0.00417)
month_3 = (month_2 + dollar)*(1+0.00417)
month_4 = (month_3 + dollar)*(1+0.00417)
month_5 = (month_4 + dollar)*(1+0.00417)
month_6 = (month_5 + dollar)*(1+0.00417)
print("6个月后,账户总额为:",month_6)
运行结果:
13.
代码:
i = int(input("投资额为:"))
ir = float(input("年利率为:"))
years = int(input("年数:"))
fv = i * (1+ir/1200)**(years*12)
print("未来投资额为:"+str(fv))
运行结果:
14.
代码:
import math
x1,y1,x2,y2,x3,y3 = eval(input("坐标分别为:"))
a = math.sqrt(((x1-x2)**2)+((y1-y2)**2))
b = math.sqrt(((x1-x3)**2)+((y1-y3)**2))
c = math.sqrt(((x2-x3)**2)+((y2-y3)**2))
A = a*math.cos((a*a - b*b - c*c)/(-2*b*c))
B = a*math.cos((b*b - a*a - c*c)/(-2*a*c))
C = a*math.cos((c*c - b*b - a*a)/(-2*a*b))
print("A=%s,B=%s,C=%s"%(A,B,C))
运行结果(不确定):
15.
代码:
import math
num = int(input("请输入边数:"))
side = float(input("边长为:"))
area = (num * (side**2))/(4 * (math.tan(math.pi/num)))
print(area)
运行结果:
16.
代码:
num = int(input("请输入一个四位整数:"))
num_first = num//1000
num_second = num%1000//100
num_third = num%100//10
num_fourth = num%10
print("%s%s%s%s"%(num_fourth,num_third,num_second,num_first))
运行结果:
17.
代码:
num = float(input("输入钱数:"))
money_point = num * 100
dollar = money_point / 100
point_remain = money_point % 100
num = point_remain/25
num_remain = point_remain%25
one_num = num_remain/10
one_remain = num_remain%10
five_num = one_remain/5
five_remain = one_remain%5
print("一美分硬币数:"+str(five_remain))
运行结果:
18.
name = str(input("Enter emloyee's name:"))
worktime = int(input("Enter number of hours worked in a week:"))
rate = float(input("Enter hourly pay rate:"))
ftw_rate = float(input("Enter federal tax withholding rate:"))
ftw_rate2 = ftw_rate * 100
stw_rate = float(input("Enter state tax withholding rate:"))
stw_rate2 = stw_rate * 100
Gross_pay = worktime * rate
fw = Gross_pay * ftw_rate
sw = Gross_pay * stw_rate
total_ded = fw + sw
Net_pay = Gross_pay - total_ded
print("Employee Name:%s"%(name))
print("Hours Worked:"+str(worktime))
print("Pay Rate:$"+str(rate))
print("Gross Pay:$"+str(Gross_pay))
print("Deuctions:")
print(" Federal withholding (%s):%s"%(ftw_rate2,fw))
print(" State Withholding (%s):%s"%(stw_rate2,sw))
print(" Total Deduction:"+str(total_ded))
print("Net Pay:"+str(Net_pay))
运行结果: