25_python实操案例十一
任务一:
try: score = int(input('请输入你的分数:')) if 0 <= score <= 100: print('分数为:', score) else: raise Exception('分数不正确') except Exception as e: print(e)
任务二:
def is_triangle(a, b, c): if a<0 or b<0 or c<0: raise Exception('三条边不能是负数') # 判断是否构成三角形 if a+b>c and b+c>a and a+c>b: print(f"三角形的边长为a={a},b={b},c={c}") else: raise Exception(f'a={a},b={b},c={c},不能构成三角形') if __name__ == '__main__': try: a = int(input('请输入第一条边')) b = int(input('请输入第二条边')) c = int(input('请输入第三条边')) is_triangle(a, b, c) except Exception as e: print(e)

浙公网安备 33010602011771号