python基础语法1-18
1.
celsius = float(input("Enter a degree in Celsius:"))
fahrenheit = (9/5)*celsius + 32
print("%s Celsius is %s Fahrenheit"%(celsius,fahrenheit))
2.
r,h = eval(input("Enter the radius and length of a cylinder:"))
area =r * r *3.14
volume = area * h
print("The area is %.4f"%area)
print("The volume is %.f"%volume)
3.
s = int(input("Enter a number between 0 and 1000:"))
a = s//100
b = s//10%10
c = s%10
sum = a+b+c
print("The sum of the digits is",sum)
4.
a = int(input("Enter the number of minutes:"))
year = int(a/60/24/365)
day = int((a-year*60*24*365)/60/24)
print("%s minutes is approximately %s years and %s days"%(a,year,day))
5.
M = float(input("Enter the amount of water in kilograms:"))
a = float(input("Enter the initial temperature:"))
b = float(input("Enter the final temperature:"))
Q = M * (b - a) * 4184
print("The energy needed is %s"%Q)
6.
a = float(input("Enter the temperature in Fahrenheit between -58 and 41:"))
b = float(input("Enter the wind speed in miles per hour:"))
t = 35.74 + 0.6215*a - 35.75*b**0.16 +0.4275*a*b**0.16
print("The wind chill index is %.5f"%t)
7.
v,a = eval(input("enter speed and acceleration:"))
length = v**2/(2*a)
print("The minimum runway length for this airplane is %.3f meters" %length)
8.
a = int(input("enter an integer:"))
b = a%10
c = a//10%10
d = a//10//10%10
e = a//1000
print("%sn%sn%sn%sn"%(b,c,d,e))
9.
import math
x1,y1,x2,y2,x3,y3 = eval(input("Enter three points for a triangle:"))
side1 = math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2))
side2 = math.sqrt((x1-x3)*(x1-x3)+(y1-y3)*(y1-y3))
side3 = math.sqrt((x2-x3)*(x2-x3)+(y2-y3)*(y2-y3))
s = (side1 + side2 + side3)/2
area = math.sqrt(s*(s-side1)*(s-side2)*(s-side3))
print(area)
10.
s = float(input("Enter the side:"))
a = (3*3**0.5/2)*s**2
print(a)
12.
a = float(input("Enter the monthly saving amount:"))
b = a * (1 + 0.00417)
b = (a + b) * (1 + 0.00417)
b = (a + b) * (1 + 0.00417)
b = (a + b) * (1 + 0.00417)
b = (a + b) * (1 + 0.00417)
b = (a + b) * (1 + 0.00417)
print(b)
13.
a = float(input("Enter investment amount:"))
b = float(input("Enter annual interest rate:"))
c = float(input("Enter number of years:"))
d = a * ((1 + b/100/12)**(c*12))
print("Accumulated value is %s" %d)
14.
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 = math.degrees(A)
B = math.degrees(B)
C = math.degrees(C)
print("三边对应的三个角为:%s, %s, %s"%(A,B,C))
15.
import math
n = int(input("Enter the number of sides:"))
s = float(input("Enter the side:"))
area = (n*s**2)/(4*math.tan(3.14/n))
print("The area of the polygon is ",area)
16.
a = int(input("Enter an integer:"))
b = a%10
c = a//10%10
d = a//10//10%10
e = a//1000
f = 1000*b+100*c+10*d+e
print("The reversed number is",f)
17.
a = float(input("输入一个十进制带小数点的数字:"))
b = a*100
c = b//100
b = b%100
d = b//25
b = b%25
e = b//10
b = b%10
f = b//5
b = b%5
sum = (100 * c +25 * d +10 * e +5 * f + b)
print(c,d,e,f,b)
print(sum)
18.
name = input("Enter employee's name:")
time = float(input("Enter number of hours worked in a week:"))
pay = float(input("Enter hourly pay rate:"))
a = float(input("Enter federal tax withholding rate:"))
b = float(input("Enter state tax withholding rate:"))
c = pay * time
d = c * a
e = c * b
f = d + e
total = c - f
print("Employee Name:",name)
print("Hours Worked:",time)
print("Pay Rate:$%s"%pay)
print("Gross Pay:$%s"%c)
print("Deductions:")
print("Federal Withholding (%s):$%.2f"%(a,d))
print("State Withholding(%s):$%.2f"%(b,e))
print("Total Deductions:$%.2f"%f)
print("Net Pay:$%.2f"%total)



