赞
踩
第1关 判断是否直角三角形
- a=eval(input())
- b=eval(input())
- c=eval(input())
- shortest=min(a,b,c)
- longest=max(a,b,c)
- middle=sum([a,b,c])-shortest-longest
- if shortest<=0 or shortest+middle<=longest:
- print('NO')
- elif shortest**2+middle**2==longest**2:
- print('YES')
- else:
- print('NO')
第2关 今年多少天?
- year=int(input())
- if year%400==0 or year%4==0 and year%100!=0:
- print('366')
- else:
- print('365')
第3关 判断三角形并计算面积
- a=float(input())
- b=float(input())
- c=float(input())
- if a+b>c and a+c>b and b+c>a:
- s=(a+b+c)/2
- area=(s*(s-a)*(s-b)*(s-c))**0.50
- print('YES')
- print(f'{area:.2f}')
- else:
- print('NO')
第4关 身高测算
- father_h=int(input())
- mother_h=int(input())
- child=input()
- if child=="男":
- child_h=(father_h+mother_h)*1.08/2
- print(int(child_h))
- elif child=="女":
- child_h=((father_h*0.923)+mother_h)/2
- print(int(child_h))
- else:
- print(f'无对应公式')
第5关 个税计算器
- n=eval(input())
- x=0
- if n<0:
- print("error")
- else:
- if(0<=n<=5000):
- x=0
- elif(0<n-5000<=3000):
- x=(n-5000)*0.03
- elif(3000<=n-5000<=12000):
- x=(n-5000)*0.1-210
- elif(12000<=n-5000<=25000):
- x=(n-5000)*0.2-1410
- elif(25000<=n-5000<=35000):
- x=(n-5000)*0.25-2660
- elif(35000<=n-5000<=55000):
- x=(n-5000)*0.30-4410
- elif(55000<=n-5000<=80000):
- x=(n-5000)*0.35-7160
- else:
- x=(n-5000)*0.45-15160
- y=n-x
- print('应缴税款'f'{x:.2f}''元,实发工资'f'{y:.2f}''元。')
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
第6关 判断闰年
- year=int(input())
- if year%400==0 or year%4==0 and year%100!=0:
- print('True')
- else:
- print('False')
第7关 分段函数B
- import math
-
- x=int(input())
- if x>=-6 and x<0:
- y=abs(x)+5
- elif 0<=x<3:
- y=math.factorial(x)
- elif 3<=x<=6:
- y=pow(x,x-2)
- else:
- y=0
- print(y)
第8关 百分制成绩转换五分制E
- grade = eval(input())
- if grade < 0 or grade > 100:
- result = "data error!"
- elif grade >= 90:
- result = "A"
- elif grade >= 80:
- result = "B"
- elif grade >= 70:
- result = "C"
- elif grade >= 60:
- result = "D"
- else:
- result = "E"
- print(result)
第9关 正负交错数列前n项和
- n = int(input())
- result = 1
- sign = -1
- pre,cur = 1,1
- for i in range(1,n):
- pre,cur = cur,pre + cur
- result = result + sign * i / cur
- sign = -sign
- print('{:.6f}'.format(result))
第10关 求数列前n项的平方和
- num = int(input())
- sum = 0
- for i in range(1, num+1):
- sum = sum + i ** 2
- print(sum)
第11关 百钱买百鸡A
- a,b,c = 0,0,0
- count = 0
- for cock in range(1,20):
- for hen in range(1,34):
- chick = 100 - cock - hen
- if cock * 5 + hen * 3 + chick / 3 == 100:
- print('{} {} {}'.format(cock, hen, chick))
第12关 用户登录C
- for i in range(3):
- user = input()
- pw = input()
- if (user == 'admin' or user == 'administrator') and (pw == '012345'):
- print('登录成功')
- break
- else:
- print('登录失败')
第13关 鸡兔同笼
- h, f = map(int,input().split())
- if (h > 0) and (f > 0) and (f >= 2 * h) and ((f - 2 * h) % 2 == 0):
- r = (f - 2 * h) // 2
- c = h - r
- print(f'有{c}只鸡,{r}只兔')
- else:
- print('Data Error!')
第14关 今天是第几天
- date = input()
- list = date.split('/')
- year = int(list[0])
- month = int(list[1])
- day = int(list[2])
- dm = [31,28,31,30,31,30,31,31,30,31,30,31]
- if year % 400 == 0 or (year % 4 == 0 and year % 100 !=0):
- dm[1] = 29
- if month == 1:
- n = day
- else:
- n = sum(dm[0:month - 1 ]) + day
- print(f'{year}年{month}月{day}日是{year}年第{n}天')
第15关 中国古代数学问题——物不知数
- n=int(input())
- flag=0
- for i in range(n+1):
- if (i%3==2) and (i%5==3) and (i%7==2):
- flag=1
- print(i)
- if flag==0:
- print('No solution!')
第16关 存款买房-B
- """
- 1.让用户输入半年度加薪的整数百分比,例如输入7表示每半年加薪7%。
- 2.第6个月后,按该百分比增加薪资。在第12个月、18个月之后,依此类推(只有在第6、12、18……等月份时才加薪)。
- 写一个程序计算需要多少个月才能攒够钱付首付款。与之前一样,假设所需的首付款百分比为0.30(30%)。
- 你的程序要给出以下提示并要求用户输入相应的数值:
- 1. 请输入总房价:total_cost
- 2. 请输入年薪:annual_salary
- 3. 请输入月存款比例:portion_saved
- 4. 每半年加薪比例:semi_annual_raise
- 测试用例
- 请输入总房价:1000000
- 请输入年薪:156800
- 请输入月存款比例:60
- 请输入加薪比例:7
- 输出:需要33 个月可以存够首付
- """
- total_cost = float(input()) # total_cost为当前房价
- annual_salary = float(input()) # 年薪
- portion_saved = float(input()) / 100 # 月存款比例,输入30转为30%
- semi_annual_raise = float(input()) /100 # 输入每半年加薪比例,输入7转化为7%
-
- portion_down_payment = 0.3 # 首付比例,浮点数
-
- ###################################Begin###################################
- # 补充你的代码 # 首付款
- ###################################Begin###################################
- down_payment=total_cost*portion_down_payment
- print('首付',down_payment)
-
- current_savings = 0 # 存款金额,从0开始
- number_of_months = 0
- monthly_salary = annual_salary/12 #月工资
- monthly_deposit = monthly_salary * portion_saved # 月存款
- # 计算多少个月才能存够首付款,结果为整数,不足1月按1个月计算,即向上取整
- ###################################Begin###################################
- # 补充你的代码
- while current_savings<down_payment:
- number_of_months=number_of_months + 1
- current_savings=current_savings + monthly_deposit
- if number_of_months %6 == 0:
- monthly_salary=monthly_salary*(1+semi_annual_raise)
- monthly_deposit=monthly_salary*portion_saved
-
-
-
- ###################################Begin###################################
- if number_of_months % 12 == 0:
- print("第{}个月月末有{:,.0f}元存款".format(number_of_months, current_savings))
-
-
- print(f'需要{number_of_months}个月可以存够首付')
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
第17关 中国古代数学问题——二鼠打洞
- wall=int(input())
- b_m,s_m,d,t=1,1,0,1
- d_b_m,d_s_m=0,0
- while wall>0:
- if wall-b_m-s_m<0:
- t=wall/(b_m+s_m)
- wall=wall-b_m-s_m
- d_b_m=d_b_m+t*b_m
- d_s_m=d_s_m+t*s_m
- b_m=2*b_m
- s_m=s_m/2
- d=d+1
- print(d)
- print(round(d_s_m,1),round(d_b_m,1))
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。