第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-longestif 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=0if 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}''元。')
第6关 判断闰年
year=int(input())if year%400==0 or year%4==0 and year%100!=0: print('True')else: print('False')
第7关 分段函数B
import mathx=int(input())if x>=-6 and x<0: y=abs(x)+5elif 0<=x<3: y=math.factorial(x)elif 3<=x<=6: y=pow(x,x-2)else: y=0print(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 = 1sign = -1pre,cur = 1,1for i in range(1,n): pre,cur = cur,pre + cur result = result + sign * i / cur sign = -signprint('{:.6f}'.format(result))
第10关 求数列前n项的平方和
num = int(input())sum = 0for i in range(1, num+1): sum = sum + i ** 2print(sum)
第11关 百钱买百鸡A
a,b,c = 0,0,0count = 0for 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] = 29if month == 1: n = dayelse: n = sum(dm[0:month - 1 ]) + day print(f'{year}年{month}月{day}日是{year}年第{n}天')
第15关 中国古代数学问题——物不知数
n=int(input())flag=0for 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_cost2. 请输入年薪:annual_salary3. 请输入月存款比例:portion_saved4. 每半年加薪比例: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_paymentprint('首付',down_payment)current_savings = 0 # 存款金额,从0开始number_of_months = 0monthly_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}个月可以存够首付')
第17关 中国古代数学问题——二鼠打洞
wall=int(input())b_m,s_m,d,t=1,1,0,1d_b_m,d_s_m=0,0while 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+1print(d)print(round(d_s_m,1),round(d_b_m,1))