当前位置:   article > 正文

python头歌实践教学平台-python第三章作业(初级)_头歌判断三角形并计算面积

头歌判断三角形并计算面积

第1关 判断是否直角三角形

  1. a=eval(input())
  2. b=eval(input())
  3. c=eval(input())
  4. shortest=min(a,b,c)
  5. longest=max(a,b,c)
  6. middle=sum([a,b,c])-shortest-longest
  7. if shortest<=0 or shortest+middle<=longest:
  8. print('NO')
  9. elif shortest**2+middle**2==longest**2:
  10. print('YES')
  11. else:
  12. print('NO')

第2关 今年多少天?

  1. year=int(input())
  2. if year%400==0 or year%4==0 and year%100!=0:
  3. print('366')
  4. else:
  5. print('365')

第3关 判断三角形并计算面积

  1. a=float(input())
  2. b=float(input())
  3. c=float(input())
  4. if a+b>c and a+c>b and b+c>a:
  5. s=(a+b+c)/2
  6. area=(s*(s-a)*(s-b)*(s-c))**0.50
  7. print('YES')
  8. print(f'{area:.2f}')
  9. else:
  10. print('NO')

第4关 身高测算

  1. father_h=int(input())
  2. mother_h=int(input())
  3. child=input()
  4. if child=="男":
  5. child_h=(father_h+mother_h)*1.08/2
  6. print(int(child_h))
  7. elif child=="女":
  8. child_h=((father_h*0.923)+mother_h)/2
  9. print(int(child_h))
  10. else:
  11. print(f'无对应公式')

第5关 个税计算器

  1. n=eval(input())
  2. x=0
  3. if n<0:
  4. print("error")
  5. else:
  6. if(0<=n<=5000):
  7. x=0
  8. elif(0<n-5000<=3000):
  9. x=(n-5000)*0.03
  10. elif(3000<=n-5000<=12000):
  11. x=(n-5000)*0.1-210
  12. elif(12000<=n-5000<=25000):
  13. x=(n-5000)*0.2-1410
  14. elif(25000<=n-5000<=35000):
  15. x=(n-5000)*0.25-2660
  16. elif(35000<=n-5000<=55000):
  17. x=(n-5000)*0.30-4410
  18. elif(55000<=n-5000<=80000):
  19. x=(n-5000)*0.35-7160
  20. else:
  21. x=(n-5000)*0.45-15160
  22. y=n-x
  23. print('应缴税款'f'{x:.2f}''元,实发工资'f'{y:.2f}''元。')

第6关 判断闰年

  1. year=int(input())
  2. if year%400==0 or year%4==0 and year%100!=0:
  3. print('True')
  4. else:
  5. print('False')

第7关 分段函数B

  1. import math
  2. x=int(input())
  3. if x>=-6 and x<0:
  4. y=abs(x)+5
  5. elif 0<=x<3:
  6. y=math.factorial(x)
  7. elif 3<=x<=6:
  8. y=pow(x,x-2)
  9. else:
  10. y=0
  11. print(y)

第8关 百分制成绩转换五分制E

  1. grade = eval(input())
  2. if grade < 0 or grade > 100:
  3. result = "data error!"
  4. elif grade >= 90:
  5. result = "A"
  6. elif grade >= 80:
  7. result = "B"
  8. elif grade >= 70:
  9. result = "C"
  10. elif grade >= 60:
  11. result = "D"
  12. else:
  13. result = "E"
  14. print(result)

第9关 正负交错数列前n项和

  1. n = int(input())
  2. result = 1
  3. sign = -1
  4. pre,cur = 1,1
  5. for i in range(1,n):
  6. pre,cur = cur,pre + cur
  7. result = result + sign * i / cur
  8. sign = -sign
  9. print('{:.6f}'.format(result))

第10关 求数列前n项的平方和

  1. num = int(input())
  2. sum = 0
  3. for i in range(1, num+1):
  4. sum = sum + i ** 2
  5. print(sum)

第11关 百钱买百鸡A

  1. a,b,c = 0,0,0
  2. count = 0
  3. for cock in range(1,20):
  4. for hen in range(1,34):
  5. chick = 100 - cock - hen
  6. if cock * 5 + hen * 3 + chick / 3 == 100:
  7. print('{} {} {}'.format(cock, hen, chick))

第12关 用户登录C

  1. for i in range(3):
  2. user = input()
  3. pw = input()
  4. if (user == 'admin' or user == 'administrator') and (pw == '012345'):
  5. print('登录成功')
  6. break
  7. else:
  8. print('登录失败')

第13关 鸡兔同笼

  1. h, f = map(int,input().split())
  2. if (h > 0) and (f > 0) and (f >= 2 * h) and ((f - 2 * h) % 2 == 0):
  3. r = (f - 2 * h) // 2
  4. c = h - r
  5. print(f'有{c}只鸡,{r}只兔')
  6. else:
  7. print('Data Error!')

第14关 今天是第几天

  1. date = input()
  2. list = date.split('/')
  3. year = int(list[0])
  4. month = int(list[1])
  5. day = int(list[2])
  6. dm = [31,28,31,30,31,30,31,31,30,31,30,31]
  7. if year % 400 == 0 or (year % 4 == 0 and year % 100 !=0):
  8. dm[1] = 29
  9. if month == 1:
  10. n = day
  11. else:
  12. n = sum(dm[0:month - 1 ]) + day
  13. print(f'{year}年{month}月{day}日是{year}年第{n}天')

第15关 中国古代数学问题——物不知数

  1. n=int(input())
  2. flag=0
  3. for i in range(n+1):
  4. if (i%3==2) and (i%5==3) and (i%7==2):
  5. flag=1
  6. print(i)
  7. if flag==0:
  8. print('No solution!')

第16关 存款买房-B

  1. """
  2. 1.让用户输入半年度加薪的整数百分比,例如输入7表示每半年加薪7%。
  3. 2.第6个月后,按该百分比增加薪资。在第12个月、18个月之后,依此类推(只有在第6、12、18……等月份时才加薪)。
  4. 写一个程序计算需要多少个月才能攒够钱付首付款。与之前一样,假设所需的首付款百分比为0.30(30%)。
  5. 你的程序要给出以下提示并要求用户输入相应的数值:
  6. 1. 请输入总房价:total_cost
  7. 2. 请输入年薪:annual_salary
  8. 3. 请输入月存款比例:portion_saved
  9. 4. 每半年加薪比例:semi_annual_raise
  10. 测试用例
  11. 请输入总房价:1000000
  12. 请输入年薪:156800
  13. 请输入月存款比例:60
  14. 请输入加薪比例:7
  15. 输出:需要33 个月可以存够首付
  16. """
  17. total_cost = float(input()) # total_cost为当前房价
  18. annual_salary = float(input()) # 年薪
  19. portion_saved = float(input()) / 100 # 月存款比例,输入30转为30%
  20. semi_annual_raise = float(input()) /100 # 输入每半年加薪比例,输入7转化为7%
  21. portion_down_payment = 0.3 # 首付比例,浮点数
  22. ###################################Begin###################################
  23. # 补充你的代码 # 首付款
  24. ###################################Begin###################################
  25. down_payment=total_cost*portion_down_payment
  26. print('首付',down_payment)
  27. current_savings = 0 # 存款金额,从0开始
  28. number_of_months = 0
  29. monthly_salary = annual_salary/12 #月工资
  30. monthly_deposit = monthly_salary * portion_saved # 月存款
  31. # 计算多少个月才能存够首付款,结果为整数,不足1月按1个月计算,即向上取整
  32. ###################################Begin###################################
  33. # 补充你的代码
  34. while current_savings<down_payment:
  35. number_of_months=number_of_months + 1
  36. current_savings=current_savings + monthly_deposit
  37. if number_of_months %6 == 0:
  38. monthly_salary=monthly_salary*(1+semi_annual_raise)
  39. monthly_deposit=monthly_salary*portion_saved
  40. ###################################Begin###################################
  41. if number_of_months % 12 == 0:
  42. print("第{}个月月末有{:,.0f}元存款".format(number_of_months, current_savings))
  43. print(f'需要{number_of_months}个月可以存够首付')

第17关 中国古代数学问题——二鼠打洞

  1. wall=int(input())
  2. b_m,s_m,d,t=1,1,0,1
  3. d_b_m,d_s_m=0,0
  4. while wall>0:
  5. if wall-b_m-s_m<0:
  6. t=wall/(b_m+s_m)
  7. wall=wall-b_m-s_m
  8. d_b_m=d_b_m+t*b_m
  9. d_s_m=d_s_m+t*s_m
  10. b_m=2*b_m
  11. s_m=s_m/2
  12. d=d+1
  13. print(d)
  14. print(round(d_s_m,1),round(d_b_m,1))

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/2023面试高手/article/detail/263537
推荐阅读
相关标签
  

闽ICP备14008679号