Python基础算法题


前言

提示:

这十六道基础语法题主要考查算数运算符


提示:以下是本篇文章正文内容,下面案例可供参考

一、十六道基础语法

#输入摄氏度转为华氏度
 cel = float(input('请输入摄氏度:'))
 f = (9 / 5) * cel + 32
 print('对应的华氏度是:' + str(f))
 print('%s摄氏度是%s华氏度'%(cel,f))

 

#计算体积
 rad = float(input('半径:'))
 length = float(input('高:'))
 area = rad * rad * 3.14;
 volume = area * length
 print("体积是:",(volume))

 

#各位整数数字求和
 a = int(input('请输入一个数'))
 b =a % 10
 c =a // 10
 d =c % 10
 e =c //10
 print('各数之和为:',b + d + e)

 

#分钟数转换为年数和天数
 minutes = int(input('请输入分钟数:'))
 years = minutes // 525600
 days = minutes % 525600 // 1440
 print('%d分钟数是%d年%d天:'%(minutes,years,days))

 

#计算能量
 M = float(input('请输入水重:'))
 initial = float(input('请输入水的最初温度'))
 final = float(input('请输入水的最终温度'))
 IN = final - initial
 Q = M * IN * 4184 
 print('需要能量为',Q)

 

#计算风寒温度
 Fa = float(input('请输入一个-58华氏度到41华氏度之间的温度:'))
 speed = float(input('请输入一个大于等于每时2公里的风速:'))
 Tw = 35.74 + 0.6215*Fa - 35.75 * speed ** 0.16 + 0.4275 * Fa * speed ** 0.16
 print('风寒温度为:',Tw)

 

#计算跑道长度
(v,a) = eval(input('请输入速度和加速度:'))
 length = v ** 2 / (2 * a)
 print('最短跑道长度:',length)

#分割数字
 a = int(input('请输入一个四位整数:'))
 b = a % 10  #---3
 b1 = a // 10 #---521
 c = b1 % 10 #--1
 c1 = b1 // 10 #---52
 d = c1 % 10 #--2
 d1 = c1 // 10 #--5
 print('%d\n%d\n%d\n%d'%(b,c,d,d1))

 

#计算三角形的面积
 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 = math.sqrt(s*(s - side1) * (s - side2) * (s - side3))
 print('三角形面积为:',area)

 

#计算正六边形的面积
 s = float(input('请输入正六边形的边长:'))
 z = (3 * (3 ** 0.5) * s ** 2) / 2
 print('正六边形的面积为:',z)

 

# 计算未来投资额
 a = int(input('请输入投资金额:'))
 b = int(input('请输入投资月数:'))
 s = a * ((1 + 0.00354) ** b)
 print('未来投资额为',s)

 

# 计算三角形的三个角
 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 * b * c))
 C = math.acos((c * c - b * b - a * a) / (-2 * b * c))
 A = round(math.degrees(A))
 B = round(math.degrees(B))
 C = round(math.degrees(C))
 print('A=%d,B=%d,C=%d'%(A,B,C))

# 计算正多边形的面积
 import math
 s = float(input('输入边长:'))
 n = int(input('这是几边形:'))
 A = (n * s ** 2) / (4 * math.tan(3.14/n))
 print('正多边形的面积为:',A)

# 分类更小货币单元
total = float(input('Enter dollas:'))
total = int(total * 100)
a = total // 100
total %= 100
b = total // 25
total %= 25
c = total // 10
total %= 10
d = total // 5
total %= 5
e= total
print('美元的个数有%d个,二角五分的硬币有%d个,一角硬币有%d个,五分硬币有%d个以及%d个美分'%(a,b,c,d,e))

  

#工资表
a = str(input("Enter employee's name:"))
b = float(input("Enter number of hours worked in a work:"))
c = float(input("Enter hourly pay rate:"))
d = float(input("Enter federal tax withholding rate:"))
e = float(input("Enter state tax withholding 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:%s" %b)
print("Pay Rate:$%s" %c)
print("Gross Pay:$%s" %f)
print("Deductions:")
print("Federal withholding(%s%%):$%s" %(g,h))
print("State withholding(%s%%):$%s" %(j,i))
print("Total Deductions::$%s" %k)
print("Net Pay:$%s" %sum)

# 金融应用程序:复利值
money = float(input('请输入你每月的存款金额:'))
money1 = money * (1 + 0.00417)
money2 = (money + money1) * (1 + 0.00417)
money3 = (money + money2) * (1 + 0.00417)
money4 = (money + money3) * (1 + 0.00417)
money5 = (money + money4) * (1 + 0.00417)
money6 = (money + money5) * (1 + 0.00417)
print('存款六个月的余额为:',money6)

总结

很好的考查对基础语法的一些应用!!!

  • 10
    点赞
  • 62
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值