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. 打印进度条>>>>

    i+1: 当前的数量 300:  总数量 import sys print("下载中...") def process(curr, count): cursor_count = c ...

  2. bsp makefile2

    1. grep "bsp_dir" -r ./  -s  --exclude-dir "*.git" 用这个加快目录定位-- 2.编译所有子目录 for dir ...

  3. (七)Create an Index

    Now let’s create an index named "customer" and then list all the indexes again: 现在让我们创建一个名 ...

  4. 安装Laravel框架,利用composer

    学一学PHP框架--Laravel的设计思想. 先安装Laravel: Laravel的文档很全:参考 http://www.golaravel.com/ 既然文档很全,就简单说下几个重点.以下以安装 ...

  5. 获取任意链接文章正文 API 功能简介

    此文章对开放数据接口 API 之「获取任意链接文章正文」进行了功能介绍.使用场景介绍以及调用方法的说明,供用户在使用数据接口时参考之用. 1. 产品功能 接口开放了根据提供的文章链接 Url 参数,智 ...

  6. 二十九、layui分页插件的使用

    <div id="page1"></div> <script> //开启分页 var page = 1; function findstoreL ...

  7. js模块化世界

    前言 我们经常见到 一些这样的写法,require('xxx').import xx from '../components/data'.export const data....也听见一些这样的说法 ...

  8. asp.net core 2.1认证

    asp.net core 2.1认证 这篇文章基于asp.net core的CookieAuthenticationHandler来讲述. 认证和授权很相似,他们的英文也很相似,一个是Authenti ...

  9. ViewPager + TabLayout + Fragment + MediaPlayer的使用

    效果图 在gradle里导包  implementation 'com.android.support:design:28.0.0' activity_main <?xml version=&q ...

  10. gitignore的使用

    gitignore的作用是忽略文件的提交,被加入到gitignore中的文件不会被提交到文件服务器 通常需要添加到.gitignore的文件有: (1)缓存相关文件,编译相关文件,运行时相关文件 (2 ...