码迷,mamicode.com
首页 > 编程语言 > 详细

[PyProj] Think in Python :

时间:2018-01-22 21:18:37      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:ack   try   ==   hand   stat   programs   erro   objects   not   

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 :

标签:ack   try   ==   hand   stat   programs   erro   objects   not   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!