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. RabbitMQ广播:fanout模式

    一. 消息的广播需要exchange:exchange是一个转发器,其实把消息发给RabbitMQ里的exchange fanout: 所有bind到此exchange的queue都可以接收消息,广播 ...

  2. css实现单行(多行)文本溢出显示 ...

    overflow: hidden; text-overflow:ellipsis; white-space: nowrap; 当然还需要加宽度width属来兼容部分浏览. 以上为单行文本溢出===== ...

  3. vue中的watch方法 实时同步存储数据

    watch 监视模式里面有个独特的方法handler 注意要加上deep: true.deep为true时,当对象的key值改变时也监听 当值发生改变被watch监视到触发了事件 开始执行handle ...

  4. laravel整理笔记(一)

    安装laravel5.8.3需要的环境 PHP >= 7.1.3 PHP OpenSSL 扩展 PHP PDO 扩展 PHP Mbstring 扩展 PHP Tokenizer 扩展 PHP X ...

  5. day22-多并发编程基础(三)

    今天学习了并发编程中的最后一部分,协程,也是python中区别于java,c等语言中很大不同的一部分 1.协程产生的背景 2.协程的概念 3.yield模拟协程 4.协程中主要的俩个模块 5.协程的应 ...

  6. 控制结构(8): 线性化(linearization)

    // 上一篇:管道(pipeline) // 下一篇:程序计数器(PC) "编程语言不过是一个工具,什么语言都一样","编程语言能改变人的思维,不同的语言会带给你不同的思 ...

  7. linux python2.x 升级python3.x

    Linux下python升级步骤  Python2 ->Python3 多数情况下,系统自动的Python版本是2.x 或者yum直接安装的也是2.x 但是,现在多数情况下建议使用3.x 那么如 ...

  8. CentOs7 最小安装版安装后配置和java环境的搭建

    下面是contos7 最小化安装成功以后进行一些基础的配置和java环境的安装教程:   1 防火墙 : 关闭防火墙: systemctl stop firewalld.service . 关闭开机启 ...

  9. P3389 【模板】高斯消元法

    高斯消元求解n元一次线性方程组的板子题: 先举个栗子: • 2x + y -   z =  8-----------① •-3x - y + 2z = -11---------② •-2x + y + ...

  10. [测试篇]MarkDown之代码块行号+折叠图片

    对比测试代码编号 $(function(){ $('pre code').each(function(){ texts = $(this).text().replace(/&(?!#?[a-z ...