实验2:Python分支结构程序设计
第二关
-阿呆-
一分耕耘,一分收获。
展开
-
第7关:求解一元二次方程
import matha=float(input("请输入系数a:"))b=float(input("请输入系数b:"))c=float(input("请输入系数c:"))s = (b**2)-(4*a*c)if (a == 0): if (b == 0): print("此方程无解!") else: print(str.format("此方程的解为:{0:.3f}", -c / b))else: if s > 0:原创 2021-10-15 08:12:40 · 3658 阅读 · 0 评论 -
第6关:三角形的面积和周长
import matha = int(input('请输入三角形的边a:'))b = int(input('请输入三角形的边b:'))c = int(input('请输入三角形的边c:'))if a+b>c and b+c>a and c+a>b: l = a + b + c p = l/2 s = math.pow(p*(p-a)*(p-b)*(p-c),0.5) print("三角形的周长={:.1f},面积={:.1f}".format(l,s原创 2021-10-15 08:12:03 · 2123 阅读 · 0 评论 -
第5关:计算分段函数的值:
from math import *x=eval(input())if x > 0: y = (pow(x,2)-3*x)/(x+1)+2*pi+sin(x)elif x == 0: y = 0else: y = log(-5*x,e) + 6*pow((abs(x)+pow(e,4)),0.5)-pow((x+1),3) print("y={}".format(y))“”"本关任务:编写程序,计算分段函数的值。从键盘输入x,根据如下公式,计算分段函数y原创 2021-10-15 08:11:21 · 5702 阅读 · 1 评论 -
第4关:工资计算
n = input()t = n.split(',')a = int(t[0])b = int(t[1])if b>120 : count = 84*1.15*(b-120)+84*120 print("{}号职工应发工资{}".format(a,count))elif 60<b<=120: count = 84*b print("{}号职工应发工资{}".format(a,count))else: count = 84*b-700原创 2021-10-15 08:10:56 · 5084 阅读 · 0 评论 -
第3关:24小时制和12小时制之间的转换
i = int(input())if i<0 or i>24: print("输入时间格式错误")else: if i>=0 and i<12: print('现在是上午{}点'.format(i)) elif i==12: print("现在是中午12点") elif i>12 and i<24: print('现在是下午{}点'.format(i-12))原创 2021-10-14 16:57:19 · 1929 阅读 · 0 评论 -
第2关:求两个整数的最大值
a = int(input())b = int(input())print('最大值:',end='')print(max(a,b))“”"本关任务:编写一个程序,实现从键盘输入的两个整数,输出两个整数的最大值。测试输入:491预期输出:最大值:91“”"原创 2021-10-14 16:55:17 · 2159 阅读 · 0 评论 -
第1关:水仙花数
n = int(input())if 100<n<999: c = n%10 b = (n%100)//10 a = n//100 if n == a**3+b**3+c**3: print('{}是水仙花数'.format(n)) else: print('{}不是水仙花数'.format(n))else: print('{}不是水仙花数'.format(n))“”"本关任务:编写一个程序,判断从键盘输原创 2021-10-14 16:53:03 · 1811 阅读 · 0 评论