代码,python1
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的更多相关文章
- 自学Python1.4-Centos内vim中文乱码问题
自学Python之路 自学Python1.4-Centos内vim中文乱码问题 1. 登陆的系统---区域语言设置 1.1查看安装中文包: 查看系统是否安装中文语言包 (列出所有可用的公共语言环境的名 ...
- 自学Python1.5-Centos内python2识别中文
自学Python之路 自学Python1.5-Centos内python2识别中文 方法一,python推荐使用utf-8编码方案 经验一:在开头声明: # -*- coding: utf-8 -*- ...
- 其它课程中的python---1、python基础
其它课程中的python---1.python基础 一.总结 一句话总结: 可以先把视频平台搭起来,这样学习效率会高很多,而且有额外收益 1.python的优势有哪些? 一个广泛的标准库 扩展性:比如 ...
- 日期格式代码出现两次的错误 ORA-01810
错误的原因是使用了两次MM . 一.Oracle中使用to_date()时格式化日期需要注意格式码 如:select to_date('2005-01-01 11:11:21','yyyy-MM-dd ...
- 可爱的豆子——使用Beans思想让Python代码更易维护
title: 可爱的豆子--使用Beans思想让Python代码更易维护 toc: false comments: true date: 2016-06-19 21:43:33 tags: [Pyth ...
- iOS代码规范(OC和Swift)
下面说下iOS的代码规范问题,如果大家觉得还不错,可以直接用到项目中,有不同意见 可以在下面讨论下. 相信很多人工作中最烦的就是代码不规范,命名不规范,曾经见过一个VC里有3个按钮被命名为button ...
- Jquery的点击事件,三句代码完成全选事件
先来看一下Js和Jquery的点击事件 举两个简单的例子 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN&q ...
- redux-amrc:用更少的代码发起异步 action
很多人说 Redux 代码多,开发效率低.其实 Redux 是可以灵活使用以及拓展的,经过充分定制的 Redux 其实写不了几行代码.今天先介绍一个很好用的 Redux 拓展-- redux-amrc ...
- 编写高质量代码:改善Java程序的151个建议(第5章:数组和集合___建议75~78)
建议75:集合中的元素必须做到compareTo和equals同步 实现了Comparable接口的元素就可以排序,compareTo方法是Comparable接口要求必须实现的,它与equals方法 ...
随机推荐
- DeveloperGuide Hive UDAF
Writing GenericUDAFs: A Tutorial User-Defined Aggregation Functions (UDAFs) are an excellent way to ...
- jdk 环境变量
1. jdk安装后的目录 2.JAVA_HOME C:\Program Files\Java\jdk1.8.0_172 3.PATH %JAVA_HOME%\bin 4.CLASSPATH .;%JA ...
- ubuntu18.04搭建hive
hive是基于Hadoop的一个数据仓库工具,可以将结构化的数据文件映射为一张数据库表,并提供简单的sql查询功能,可以将sql语句转换为MapReduce任务进行运行. 其优点是学习成本低,可以通过 ...
- php7 的yum源
yum源默认的版本太低了,手动安装有一些麻烦,想采用Yum更新安装的可以使用下面的方案: 1.检查当前安装的PHP包 yum list installed | grep php 如果有安装的PHP包, ...
- 理解MySQL数据库事务
1. 什么是事务处理? 事务处理是一种机制,它是用来管理必须成批执行的mysql操作.来保证数据库不完整的操作结果. 2. 为什么要使用事务处理? 在使用mysql操作数据的过程中,如果只是简单的中小 ...
- C++笔记-数组指针/二维数组转换指针
参考资料: 1. 作者 BensonLaur :https://www.cnblogs.com/BensonLaur/p/6367077.html 2. https://blog.csdn.net/ ...
- Minieye杯第十五届华中科技大学程序设计邀请赛网络赛D Grid(简单构造)
链接:https://ac.nowcoder.com/acm/contest/560/D来源:牛客网 题目描述 Give you a rectangular gird which is h cells ...
- linux安装tomcat部署web项目
我用的是如下图的两个软件,连接linux服务器. 其中WinSCp是传输文件用的,SecureCRT是用来输入命令的. 1.复制tomcat到指定目录(可复制到你想要的目录下),命令如下: cp /路 ...
- Crypto加密解密
crypto 模块提供了加密功能,包含对 OpenSSL 的哈希.HMAC.加密.解密.签名.以及验证功能的一整套封装.我们这里讲crypto AES算法加密 一.使用步骤 1.引入Crypto 1. ...
- vue环境的搭建与第一个demo
参考两个博客 1 2 git.npm和淘宝镜像的安装过程过程省略了,直接开始webpack + vue-cli + 创建demo 首先,在磁盘创建一个文件夹,命名为vue-projects,里面再建一 ...