Demo01
#Demo01 温度转化
celsius = float(input("Enter a degree in Celsius:"))
fahrenheit = (9/5) * celsius + 32
print(celsius," Celsius is ",fahrenheit,"fahrenheit")
Demo02
#Demo2 计算圆柱体的体积
radius,length = eval(input("Enter the radius and length of a coylinder:"))
area = radius * radius * 3.14
volume = area * length
print("The area is ",area)
print("The Volume is ",volume)
Demo03
#Demo03 对一个整数中的数字求和
num = float(input("Enter a number between 0 and 1000:"))
a = num % 10
b = (num // 10) %10
c = num //100
sum = a + b + c
print("THe sum of the digits is ",sum)
Demo04
#Demo4 计算年数和天数
Minute = float(input("Please enter minutes:"))
Time = 24 * 60
Year = Minute//(Time*365)
Day = Minute%(Time*365)//Time
print("%d年%d天"%(Year,Day))
Demo05
#Demo5 计算能量
M = float(input("ENter the amount of water in kilograms:"))
initialTemperature = float(input("ENter the initial temperature:"))
finalTemperature = float(input("ENter the final temperature:"))
Q = M * (finalTemperature - initialTemperature) * 4184
print("The energy needed is ",Q)
Demo06
#Demo06 风寒温度
ta = float(input("Enter the temperature in Fahrenheit between -58 and 41:"))
v = float(input("Enter the wind speed in miles per hour:"))
twc = 35.74 + 0.6215*ta - 35.75*v**0.16 + 0.4275*ta*v**0.16
print("The wind chill index is ",twc)
Demo07
#Demo07 计算跑道长度
v = float(input("Enter speed:"))
a = float(input("Enter acceleration:"))
length = (v**2) / (2*a)
print("The minimum runway length for this airplane is ",length,"meters")
Demo08
#Demo08 分割数字
num = int(input("Enter an integer:"))
a = num % 10
b = (num // 10) % 10
c = (num // 100) % 10
d = num // 1000
print(a)
print(b)
print(c)
print(d)
Demo09
#Demo09
import math
x1, y1, x2, y2, x3, y3 =eval(input("Enter three points for a triangle: "))
sidel1 = math.sqrt((x1-x2)**2 + (y1-y2)**2)
sidel2 = math.sqrt((x2-x3)**2 + (y2-y3)**2)
sidel3 = math.sqrt((x3-x1)**2 + (y3-y1)**2)
s = (sidel1 + sidel2 +sidel3)/2
area = math.sqrt(s*(s-sidel1)*(s-sidel2)*(s-sidel3))
print("The area of the triangle is ",area)
Demo10
import math
s = float(input("Enter the side: "))
area = (3* math.sqrt(3)/2)*s**2
print("The area of the hexagon is ",area)
Demo11
NULL
Demo12
#Demo12 复利值
money = float(input("Enter the monthly saving amount: "))
M1 = money * (1+0.00417)
M2 = (M1 + 100) * (1 + 0.00417)
M3 = (M2 + 100) * (1 + 0.00417)
M4 = (M3 + 100) * (1 + 0.00417)
M5 = (M4 + 100) * (1 + 0.00417)
M6 = (M5 + 100) * (1 + 0.00417)
print("After the sixth month, the account value is ",M6)
Demo13
#Demo13 计算未来投资金额
money = int(input("Enter investment amount: "))
tzl = float(input("Enter annual interest rate: "))
year = int(input("ENter number of years: "))
tzl1 = tzl/100
year1 = year * 12
Value = money * (1 + tzl1)**year
print("Accumlated Value is ",Value)
Demo14
import math
x1, y1, x2, y2, x3, y3 =eval(input("Enter three points for a triangle: "))
a = math.sqrt((x1-x2)**2 + (y1-y2)**2)
b = math.sqrt((x2-x3)**2 + (y2-y3)**2)
c = math.sqrt((x3-x1)**2 + (y3-y1)**2)
A = a * math.cos((a * a - b * b - c * c)/(-2 *b * c))
B = a * math.cos((a * a - b * b - c * c)/(-2 *a * c))
C = a * math.cos((a * a - b * b - c * c)/(-2 *a * b))
print(A)
print(B)
print(C)
Demo15
#Demo15 一个正多边形的面积
import math
n = int(input("Enter the number of sides: "))
s = float(input("Enter the side: "))
Area = (n*(s**2))/(math.tan(3.14/n)*4)
print("The area of the polygon is ",Area)
Demo16
#Demo16 反向数字
num = float(input("Enter an integer: "))
a = num % 10
b = ((num // 10) % 10)
c = ((num // 100) % 10)
d = num // 1000
print("The reversed number is %d%d%d%d"%(a,b,c,d))
Demo17
#Demo17 美分
num = float(input("Please enter a decimal number with a decimal point: "))
Penny = num * 100
Dollar_number = Penny / 100
Remainder_Penny = Penny % 100
Quarter_number = Remainder_Penny / 25
Remainder2_Penny = Remainder_Penny % 25
Dime_number = Remainder2_Penny / 10
Remainder3 = Remainder2_Penny % 10
Jitney = Remainder3 / 5
Remainder4 = Remainder3 % 5
Penny_number = Remainder4
print("The Penny number is ",Penny_number)
Demo18
#Demo18 工资表
name = input("Enter employee's name: ")
time = float(input("Enter number of hours worked in a week: "))
pay1 = float(input("Enter hourly pay rate:"))
federa_tax_rate = float(input("Enter federal tax withholding rate: "))
State_tax_rate = float(input("Enter state tax withholding rate: "))
print(" ")
print("Employee Name: ",name)
print("Hours worked: ",time)
print("Pay Rate: $",pay1)
print("Gross pay: $",time*pay1)
print("Deductions:")
print(" federal withholding(20.0%): $",time * pay1 * federa_tax_rate)
print(" State withholding (9.0%): $",time * pay1 * State_tax_rate)
print(" Total Deduction: $",time * pay1 * federa_tax_rate + time * pay1 * State_tax_rate)
print(" Net Pay: $",time*pay1-(time * pay1 * federa_tax_rate + time * pay1 * State_tax_rate))