Demo08
# 8.分割数字
number = int(input("Enter an integer:") )
_num1 = number % 10 #取余数 输入数字的倒数第一个数
_num2 = number // 10 #取千位,百位和十位数
_num3 = _num2 % 10 # 取余数 输入数字的倒数第二个数
_num4 = _num2 // 10 #取千位和百位数
_num5 = _num4 % 10 # 取余数 输入数字的倒数第三个数
_num6 = _num4 // 10 #取千位 _num7 = _num6 % 10 # 取余数 输入数字的倒数第四个数
print("%d\n%d\n%d\n%d\n"%(_num1 ,_num3 ,_num5 ,_num7 ) )
#分割数字
n = input()
rev_n = n[::-1]
print(" ".join(rev_n))
Demo09
#三角形面积
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 = float((math.sqrt(s * (s - side1) * (s - side2) * (s - side3))))
print("这个三角形的面积为%.2f" %(area))
Demo10
#正六边形的面积
import math
s = float(input("请输入正六边形的边长:"))
area = ((3 * (3 ** 0.5)) / 2) * s * s
print("正六边形的面积是%s"%(area))
Demo11
#当前时间
Demo12
#金融应用程序:复利值
a = float(input("请输入存款数:"))
one = a * (1 + 0.00417)
two = (100 + one) * (1 + 0.00417)
three = (100 + two) * (1 + 0.00417)
four = (100 + three) * (1 + 0.00417)
five = (100 + four) * (1 + 0.00417)
six = (100 + five) * (1 + 0.00417)
print("六个月后的账户总额为%.2f"%(six))
Demo13
#金融应用程序:计算未来投资额
amount = float(input("请输入投资额:"))
rate = float(input("请输入年利率:"))
years = float(input("请输入年数:"))
value = amount * (1 + rate * 0.01) ** years
print("未来投资总额是%.2f"%(value))
Demo14
#计算三角形的三个角
import math
a,b,c = eval(input("请输入三条边的长度:"))
A = math.acos((a * a - b * b - c * c) / (-2 * b * c))
B = math.acos((b * b - a * a - c * c) / (-2 * a * c))
C = math.acos((c * c - b * b - a * a) / (-2 * a * b))
A = round(math.degrees(A))
B = round(math.degrees(B))
C = round(math.degrees(C))
print("A = %s°,B = %s°,C = %s°"%(A,B,C))
Demo15
#一个正多边形的面积
import math
n = float(input("请输入正多边形的边数:"))
s = float(input("请输入正多边形的边长:"))
area = (n * s **2) / (4 * math.tan(3.14 / n))
print("%s正多边形的面积为%.10f"%(n,area))
Demo16
number = int(input("请输入一个四位整数:") )
num1 = number % 10 #取余数 输入数字的倒数第一个数
num2 = number // 10 #取千位,百位和十位数
num3 = num2 % 10 # 取余数 输入数字的倒数第二个数
num4 = num2 // 10 #取千位和百位数
num5 = num4 % 10 # 取余数 输入数字的倒数第三个数
num6 = num4 // 10 #取千位
num7 = num6 % 10 # 取余数 输入数字的倒数第四个数
print("颠倒后的数为 %s%s%s%s"%(num1,num3,num5,num7))
Demo17
x = float(input("Enter dollas:"))
x = int(x * 100)
a = x // 100
x %= 100
b = x // 25
x %= 25
c = x // 10
x %= 10
d = x // 5
x %= 5
e = x
print("美元的个数有%s个,二角五分的硬币有%s个,一角硬币有%s个,五分硬币有%s个以及%s个美分"%(a, b, c, d, e))
Demo18
# 18.工资表
a = str(input("Enter employee's name :"))
b = float(input("Enter number of hours worked in a week:"))
c = float(input("Enter hourly pay rate:"))
d = float(input("Enter federal tax withholding rate:"))
e = float(input("Enter state tax wi thholding rate:"))
f = c * 10 g = d * 100 h = f * 0.2 i = f * 0.09 j = e * 100 k = h + i sum = f - k print("\nEmployee Name: %s" %a )
print("Hours Worked: %.1f" %b )
print("Pay Rate: $%.2f" %c)
print("Gross Pay: $%.1f" %f )
print("Deductions:")
print(" Federal Wi thholding (%.1f%%):$%.2f" % (g,h))
print(" State Wi thholding (%.1f%%): $%.2f" % (j,i))
print(" Total Deduction:: $%.2f"%k)
print("Net Pay: $%.2f"%sum )