def main():
try:
number1,number2=eval(input("please enter two number"))
result=number1/number2
except ZeroDivisionError:
print("the division is 0",result)
except SyntaxError:
print("syntax is wrong")
else:
print("ok the result is ",result)
finally:
print("i don't know")
main()

 Python 3.6.1rc1 (v3.6.1rc1^0:e0fbe5feee4f9c00f09eb9659c2182183036261a, Mar  4 2017, 20:00:12) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
= RESTART: C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py =
please enter two number1 3
syntax is wrong
i don't know
>>> main()
please enter two number1,2
ok the result is 0.5
i don't know
>>> main()
please enter two number
syntax is wrong
i don't know
>>> main()
please enter two number1,0
i don't know
Traceback (most recent call last):
File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 4, in main
result=number1/number2
ZeroDivisionError: division by zero During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "<pyshell#3>", line 1, in <module>
main()
File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 6, in main
print("the division is 0",result)
UnboundLocalError: local variable 'result' referenced before assignment
>>> main()
please enter two number1.1,0.0
i don't know
Traceback (most recent call last):
File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 4, in main
result=number1/number2
ZeroDivisionError: float division by zero During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "<pyshell#4>", line 1, in <module>
main()
File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 6, in main
print("the division is 0",result)
UnboundLocalError: local variable 'result' referenced before assignment
>>>
= RESTART: C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py =
please enter two number
1,1
ok the result is 1.0
i don't know
>>> python2.py
Traceback (most recent call last):
File "<pyshell#5>", line 1, in <module>
python2.py
NameError: name 'python2' is not defined
>>> pytho2.py
Traceback (most recent call last):
File "<pyshell#6>", line 1, in <module>
pytho2.py
NameError: name 'pytho2' is not defined
>>> main
<function main at 0x0000013B8E633E18>
>>> main()
please enter two number
1.1,0.0
i don't know
Traceback (most recent call last):
File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 4, in main
result=number1/number2
ZeroDivisionError: float division by zero During handling of the above exception, another exception occurred: Traceback (most recent call last):
File "<pyshell#8>", line 1, in <module>
main()
File "C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py", line 6, in main
print("the division is 0")
UnboundLocalError: local variable 'result' referenced before assignment
>>>
= RESTART: C:/Users/lenovo/AppData/Local/Programs/Python/Python36/pytho2.py =
please enter two number
1,0
the division is 0
i don't know
>>>

2.

 def root():
try:
print("please enter threes numbers:\n")
a,b,c=input("yes please such as(z,x,y)")
discRoot=math.sqrt(b*b-4*a*c)
root1=(-b+discRoot)/(2*a)
root2=(-b-discRoot)/(2*a)
print("the root is",root1,root2)
except ValueError:
print("\n no really root)
root()

冒号忘了,还有:eval()

修后如下:

 import math
def main1():
try:
number1,number2=eval(input("please enter two number\n"))
result=number1/number2
#except ZeroDivisionError:
# print("the division is 0")
except ZeroDivisionError:
print("the division is 0")
except SyntaxError:
print("syntax is wrong")
else:
print("ok the result is ",result)
finally:
print("i don't know") def root():
try:
print("please enter threes numbers:\n")
a,b,c=eval(input("yes please such as(z,x,y):"))
print("www")
discRoot=math.sqrt(b * b - 4 * a * c)
print("hey here")
root1=(-b+discRoot)/(2*a)
root2=(-b-discRoot)/(2*a)
print("the root is",root1,root2)
except ValueError:
print("\n no really root")
root()

代码,python1的更多相关文章

  1. 自学Python1.4-Centos内vim中文乱码问题

    自学Python之路 自学Python1.4-Centos内vim中文乱码问题 1. 登陆的系统---区域语言设置 1.1查看安装中文包: 查看系统是否安装中文语言包 (列出所有可用的公共语言环境的名 ...

  2. 自学Python1.5-Centos内python2识别中文

    自学Python之路 自学Python1.5-Centos内python2识别中文 方法一,python推荐使用utf-8编码方案 经验一:在开头声明: # -*- coding: utf-8 -*- ...

  3. 其它课程中的python---1、python基础

    其它课程中的python---1.python基础 一.总结 一句话总结: 可以先把视频平台搭起来,这样学习效率会高很多,而且有额外收益 1.python的优势有哪些? 一个广泛的标准库 扩展性:比如 ...

  4. 日期格式代码出现两次的错误 ORA-01810

    错误的原因是使用了两次MM . 一.Oracle中使用to_date()时格式化日期需要注意格式码 如:select to_date('2005-01-01 11:11:21','yyyy-MM-dd ...

  5. 可爱的豆子——使用Beans思想让Python代码更易维护

    title: 可爱的豆子--使用Beans思想让Python代码更易维护 toc: false comments: true date: 2016-06-19 21:43:33 tags: [Pyth ...

  6. iOS代码规范(OC和Swift)

    下面说下iOS的代码规范问题,如果大家觉得还不错,可以直接用到项目中,有不同意见 可以在下面讨论下. 相信很多人工作中最烦的就是代码不规范,命名不规范,曾经见过一个VC里有3个按钮被命名为button ...

  7. Jquery的点击事件,三句代码完成全选事件

    先来看一下Js和Jquery的点击事件 举两个简单的例子 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...

  8. redux-amrc:用更少的代码发起异步 action

    很多人说 Redux 代码多,开发效率低.其实 Redux 是可以灵活使用以及拓展的,经过充分定制的 Redux 其实写不了几行代码.今天先介绍一个很好用的 Redux 拓展-- redux-amrc ...

  9. 编写高质量代码:改善Java程序的151个建议(第5章:数组和集合___建议75~78)

    建议75:集合中的元素必须做到compareTo和equals同步 实现了Comparable接口的元素就可以排序,compareTo方法是Comparable接口要求必须实现的,它与equals方法 ...

随机推荐

  1. Django 【orm】或

    方式一: q=Q() q.connection="or" q.children.append(("pk",1)) q.children.append((&quo ...

  2. webpack开发环境和生产环境切换原理

    在package.json中有如下设置: "scripts": {    "dev": "node build/dev-server.js" ...

  3. R语言学习——因子

    变量可分为名义型变量.有序型变量或者连续型变量.名义型变量是没有顺序之分的类别变量,如糖尿病类型Diabetes(Type1.Type2),即使在数据中Type1编码为1而Type2编码为2,这也并不 ...

  4. WEB框架-Django组件学习-分页器学习

    1.分页器基础学习 1.1 补充知识-批量创建 数据库中数据批量创建,不要每创建一个就往数据库中塞一个,会造成撞库,造成大量I/O操作,速速较慢,应该采用一次性创建大量数据,一次性将大量数据塞入到数据 ...

  5. [LeetCode] 10. 正则表达式匹配

    题目链接:https://leetcode-cn.com/problems/regular-expression-matching/ 题目描述: 给定一个字符串 (s) 和一个字符模式 (p).实现支 ...

  6. 2019-03-23 shell练习,日志统计

    [2019-03-10 17:44:55]1234567 paid 10 10000 cat test.txt |tail -n +1 |sed 's/]/ ]g' |awk '{count[$3]+ ...

  7. kubernetes1.14.0部署

    2019/4/6/使用kubeadm安装部署kubernetes集群: 前提:1.各节点时间同步:2.各节点主机名称解析:dns OR hosts:3.各节点iptables及firewalld服务被 ...

  8. AWT的应用

    AWT(Abstract Window TookIT)是java用于创建用户界面和绘制图形的所有类 AWT组件和容器 AWT包含了很多类和接口,用于java Application的GUI(图形用户界 ...

  9. 妙谈js回调函数的理解!

    很有共鸣,之前也是一直对回调函数感觉不明不白的,自己也看了不少解释说明.后来我觉得造成很多人对回调理解困难的一个原因就是,我在开发中见到的大多数使用了回调函数的情况都是直接上来就 传一个回调函数进去 ...

  10. PS调出唯美紫蓝色天空背景女生照片

    教你学会用PS给照片叠加素材,达到想要的效果. 首先,作为摄影在拍摄前,我们要明白自己拍摄主题与目的,希望后期达到的效果,尤其是当我们需要后期叠加素材时,脑海中自然而然会有大致画面,就以“夏日”这组为 ...