python❀运算符号作业

Demo01
'''
数据:华氏温度 摄氏温度
指令:
1、提示用户输入华氏温度
2、将华氏温度转换摄氏温度
3、输出转化后的值
'''
Celsius = float(input("Enter a degree in Celsius:"))
fah = (9 / 5) * Celsius +32
print("%.0f Celsius is %.1f Fa"%(Celsius,fah))
#.0保留0位小数、 .1保留一位小数

Demo02
'''
数据:圆柱高、底面圆半径
指令:
1、提示输入:高、半径
2、分别计算面积和体积
3、输出数据
'''
radius,length = eval(input("Enter the radius and length a cylinder:"))
π = 3.1415926
area = radius * radius * π
volume = area * length
print("The area is:%f\nThe volume is:%d"%(area,volume))

Demo03
"""
数据:输入一个三位数 个位 十位 百位
步骤:
1.输入一个不超过三位的数字num=123
2.num对10取余 得到 个位 3 - num1
3.num整除10 12
4.num对10取余 得到 十位 2 - num2
5.num整除10 1
6.num对10取余 得到 百位 1 - num3
7.将num1+num2+num3
"""
number = int(input("Enter a number between 0 and 1000:"))
number = abs(number)
num1 = number % 10
number = number // 10
num2 = number % 10
number = number // 10
num3 = number % 10
total = num1 + num2 + num3
# print("The sum of the digits is " + str(total))
print("The sum of the digits is ", total)

Demo04
'''
步骤:1、输入分钟数
    2、将分钟转化为天数和年数
    3、输出天数和年数
'''
minutes = int(input('Enter the number of minuyes:'))
days = minutes / 1440
years = days / 365
print('%.0f minutes is approximately %.0f years and %.0f days'%(minutes,years,days))

Demo05
'''
数据:千克 M、 最终温度 finalTemperature 、 初始温度 initialTemperature
步骤:1、输出三个数据
     2、计算出所需热量Q
     3、输出所需热量
'''
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 %0.1f"%Q)

Demo06
'''
数据:华氏度、风速
步骤:1、输入参数
    2、计算风寒温度
    3、输出风寒温度
'''
temperature = float(input("Enter the temperature in Fahrenheit between -58 and 41 : "))
speed = float(input("Enter the wind speed in miles per hour:"))
chill = 35.74 + 0.6215 * temperature - 35.75 * (speed ** 0.16) + 0.4275 * temperature * (speed ** 0.16)
print('The wind chill index is :%f'%chill)

Demo07
'''
数据:加速度a、起飞速度v
步骤:1、输入参数
    2、计算最短跑道长度
    3、输出求得参数
'''
v,a = eval(input("Enter speed an acceleration:"))
length = (v ** 2) / (2 * a)
print('The minimum runway length for this airplane is :%f meters'%length)

Demo08
"""
数据:输入一个四位数 个位 十位 百位 千位
步骤:
1.输入一个四位的数字num=1234
2.num对10取余 得到 个位 4 - num1
3.num整除10
4.num对10取余 得到 十位 3 - num2
5.num整除10
6.num对10取余 得到 百位 2 - num3
7.num整除10
8.num对10取余 得到 百位 1 - num4

"""
integer = int(input('Enter an integer:'))
num1 = integer % 10
integer = integer // 10
num2 = integer % 10
integer = integer // 10
num3 = integer % 10
integer = integer // 10
num4 = integer % 10
print('%d\n%d\n%d\n%d'%(num1,num2,num3,num4))

Demo09
"""
数据:三个点的坐标 x1y1 x2y2 x3y3
步骤:
1.提示用输入三个点坐标
2.两两计算边长
3.计算半周长s
4.计算面积
"""
x1, y1, x2, y2, x3, y3 = eval(input("Enter three points for a triangle:"))
side1 = ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5
side2 = ((x3 - x1) ** 2 + (y3 - y1) ** 2) ** 0.5
side3 = ((x2 - x3) ** 2 + (y2 - y3) ** 2) ** 0.5
s = (side1 + side2 + side3) / 2
area = (s * (s - side1) * (s - side2) * (s - side3)) ** 0.5
print("The area of the triangle is %.1f" % area)
Demo12

```python
'''
数据:账户金额
步骤:1、用户输入金额
     2、带入公式,算出六个月后的金额
     3、输出
'''
monthly = float(input('Enter the monthly saving amount:'))

value1 = (monthly * (1 + 0.00417))
value2 = float(monthly + value1) * (1 + 0.00417)
value3 = (monthly + value2) * (1 + 0.00417)
value4= (monthly + value3) * (1 + 0.00417)
value5 = (monthly + value4) * (1 + 0.00417)
value6 = (monthly + value5) * (1 + 0.00417)
print('After the sixth month,the account value is %0.2f'%value6)

Demo13

'''
数据:投资额 月投资额 月数
步骤:1、输入参数
    2、带入公式
    3、输出为例投资额
'''
amount = float(input('Enter investmen amount:'))
rate = float(input('Enter annual interest rate:'))
month = float(input('Enter number of month:'))
vlaue = amount * ((1 + ((rate * 0.01) / 12)) ** month)
print('Accumlated value is %0.2f'%vlaue)

Demo15

'''
数据:边数、正多边形边长
步骤:1、输入边长数据
    2、根据公式计算面积
    3、输入面积
'''
import math
number = float(input('Enter the number of sides:'))
side = float(input('Enter the side:'))
area = (number * (side ** 2)) / (4 * math.tan(math.pi/ number))
print('The area of the polygon is %f'%area)

Demo16

'''
步骤:1、输入一个四位数
    2、把个位十位百位千位剥离出来
    3、反向输出
'''
integer = int(input('Enter an integer:'))
num1 = integer % 10
integer = integer // 10
num2 = integer % 10
integer = integer // 10
num3 = integer % 10
integer = integer // 10
num4 = integer % 10
print('%d%d%d%d'%(num1,num2,num3,num4))

Demo18

'''
数据:姓名、一周工作时间、每小时报酬、联邦税率、州预扣税率
步骤:1、输入参数
    2、计算出税后所得和扣税多少
    3、输出
'''
name = str(input('Enter employee‘s name:'))
hours = float(input('Enter number of hours worked in a week:'))
hourly = float(input('Enter hourly pay rate:'))
federal = float(input('Enter federal tax withholding rate:'))
state = float(input('Enter state tax withholding rate:'))
a = hours * hourly
b = a * 0.2
c = a * 0.09
d = b + c
e = a - d

print('Employee Name:%s'%name)
print('Hours Worked:%.2f'%hours)
print('Pay Rate:$%.2f '%hourly)
print('Gross Pay:$%.2f'%a)
print('Deductions:')
print('\tFederal Withholding(0.2):$%.2f'%b)
print('\tState Withholding(0.09):$%.2f'%c)
print('\tTotal Deduction:$%.2f'%d)
print('Net Pay:$%.2f'%e)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值