前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >Python异常处理(下)

Python异常处理(下)

原创
作者头像
陈不成i
修改2021-06-18 18:08:45
2630
修改2021-06-18 18:08:45
举报
文章被收录于专栏:ops技术分享ops技术分享

三.实例

  1. def boxPrint(symbol, width, height):
  2. if len(symbol) != 1:
  3. raise Exception('Symbol must be a single character string.')
  4. if width <= 2:
  5. raise Exception('Width must be greater than 2.')
  6. if height <= 2:
  7. raise Exception('Height must be greater than 2.')
  8. print(symbol * width) #打印
  9. for i in range(height - 2):
  10. print(symbol + (' ' * (width - 2)) + symbol)
  11. print(symbol * width)
  12. for sym, w, h in (('*', 4, 4), ('O', 20, 5), ('x', 1, 3), ('ZZ', 3, 3)):
  13. try:
  14.         boxPrint(sym, w, h)
  15. except Exception as err: #返回自定义错误
  16. print('An exception happened: ' + str(err))

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。

如有侵权,请联系 cloudcommunity@tencent.com 删除。

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 三.实例
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档