当前位置:网站首页>写一个方法sanjiao(a, b, c),判断三个参数是否能构成一个三角形,如果不能则抛出异常IllegalArgumentException,显示异常信息a,b,c”不能构成三角形”,如果可以
写一个方法sanjiao(a, b, c),判断三个参数是否能构成一个三角形,如果不能则抛出异常IllegalArgumentException,显示异常信息a,b,c”不能构成三角形”,如果可以
2022-04-22 06:12:00 【欣慰的三叶草(● ̄(エ) ̄●)】
1、写一个方法sanjiao(a, b, c),判断三个参数是否能构成一个三角形,如果不能则抛出异常IllegalArgumentException,显示异常信息a,b,c”不能构成三角形”,如果可以构成则显示三角形三个边长,在方法中得到命令行输入的三个整数,调用此方法,并捕获异常。
class SanJiao:
def sanjiao(self,a, b, c):
try:
if a + b > c and a + c > b and b + c > a:
print('三角形的三边长分别为:{}、{}、{}'.format(a, b, c))
else:
raise Exception('IllegalArgumentException!')
except Exception as error:
print('Error:',error,'a,b,c”不能构成三角形”')
a = SanJiao()
print('第一种情况:')
a.sanjiao(1, 2, 3)
print()
print('第二种情况:')
a.sanjiao(3, 4, 5)

版权声明
本文为[欣慰的三叶草(● ̄(エ) ̄●)]所创,转载请带上原文链接,感谢
https://blog.csdn.net/cygqtt/article/details/106489083
边栏推荐
- 分布式任务调度与计算框架:PowerJob 快速开始(本地IDE版) 02
- Matlab: female voice to male voice
- Noi / 1.5.25: finding special natural numbers
- jeecg项目部署笔记
- STM32 timer generates event Tim_ GenerateEvent
- Zhejiang University Edition "C language programming (3rd Edition)" topic set exercise 7-4 find out the elements that are not common to two arrays
- What is the learning route of switching to digital IC Verification? Is there time to start turning now? 985 master's degree, second year of Graduate School of Electronics
- JS实现点击头像上传图片修改
- 泛型与反射的实际使用练习(包含一个泛型缓存)----手写ORM框架
- 实验室安全考试
猜你喜欢

SeekBar 自定义 样式 详解

Minipcie interface can card expands can channel for industrial computer

Introduction to IC Analog Layout - learning notes on layout Basics (I)

【Bug小记】input:-webkit-autofill:输入框自动填充背景问题

Comparison and improvement of Nacos service registration center

Service configuration center of Nacos

Preparation before analog circuit board commissioning_ Analog circuit board

RSS pit entry Guide

微信小程序 canvas 画简单的仪表盘 渐近色

Quotient principle of modular division
随机推荐
leetcode598:范围求和II
.NET学习笔记----关于.NET Core那些事(1)【.netcore的项目结构、五种向页面传值的方式、Log4Net和NLog的使用】
Is digital IC design promising? How about career development and salary?
安裝和修改uTools及vscode插件安裝路徑
How to become an IC Verification Engineer?
Introduction to IC Analog Layout - learning notes on layout Basics (2)
Li Kou 299: number guessing game
Preparation before analog circuit board commissioning_ Analog circuit board
【Bug小记】keepalive下mounted只执行一次
A solution to the error of selecting objects in pyautocad
Distributed task scheduling and computing framework: powerjob advanced features - OpenAPI 04
Eight functions of random library
Introduction to IC Analog Layout - learning notes on layout Basics (I)
.NET学习笔记----关于.NET Core那些事(3)【配置文件的读取、json文件的通用解析、读取静态文件】
Installer et modifier les chemins d'installation des plug - ins utools et vscode
老程序员常逛的网站(持续更新)
pyautocad 选择对象报错的解决方案
泛型与反射的实际使用练习(包含一个泛型缓存)----手写ORM框架
Nacos服务提供者注册
Review of the sixth edition of introduction to software engineering (notes)