首页 > 编程语言 > 详细

[PyProj] Think in Python :

时间:2018-01-22 21:00:56      阅读:327      评论:0      收藏:0      [点我收藏+]

1. Programs are composed of modules.
2. Modules contain statements.
3. Statements contain expressions.
4. Expressions create and process objects.

 

Handling Errors by Testing Inputs

"""
(1) 判断输入
"""
while
True:   reply = input(Enter text:)
  
if reply == stop:     break   elif not reply.isdigit():     print(Bad! * 8)   else:     print(int(reply) ** 2) print(Bye) """
(2) 输入不是数字怎么办?
""" # 方法一
while True:   reply = input(Enter text:)   if reply == stop: break
  # 如果非法str,执行except   try:     num = int(reply)   except:     print(Bad! * 8)   else:     print(num ** 2) print(Bye) # 方法二 while True:   reply = input(Enter text:)   if reply == stop:     break   elif not reply.isdigit():  # 如果不是数字     print(Bad! * 8)   else: # 如果是数字     num = int(reply)     if num < 20:       print(low)     else:       print(num ** 2) print(Bye)

 

[PyProj] Think in Python :

原文:https://www.cnblogs.com/jesse123/p/8331016.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!