代码,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方法 ...
随机推荐
- Git 生成SSH Key
背景:服务器是LINUX系统(centos7),使用GitLab管理git代码库.各个客户端通过sourcetree 工具,采用SSH获取.提交代码.使用SSH的方式需要公钥和私钥.下面介绍秘钥的生成 ...
- day2 and day3 总结-python基础-坚持就是胜利
今日份快捷键学习,pycharm中按CTRL+ALT+L 自动规范化操作,不过和QQ的快捷键会有冲突,建议更改QQ的 知识点: 1.编码 2.while循环 3.运算符 4.数字int 5.布尔值 6 ...
- 使用 Linux 文件恢复工具
使用 Linux 文件恢复工具 Linux 文件恢复的原理 inode 和 block 首先简单介绍一下 Linux 文件系统的最基本单元:inode.inode 译成中文就是索引节点 ...
- 3-STM32带你入坑系列(自己封装点亮一个灯的库--Keil)
2-STM32带你入坑系列(点亮一个灯--Keil) 首先建一个stm32f103x.h的文件,然后 #include "stm32f103x.h" 还记得上一节 现在呢就是做一个 ...
- 基于 HTML5 的 WebGL 自定义 3D 摄像头监控模型
前言 随着视频监控联网系统的不断普及和发展, 网络摄像机更多的应用于监控系统中,尤其是高清时代的来临,更加快了网络摄像机的发展和应用. 在监控摄像机数量的不断庞大的同时,在监控系统中面临着严峻的现状问 ...
- cmd执行超大sql文件
osql -S 127.0.0.1 -U sa -P 123456 -i d:\test.sql osql为SQL Server的命令,要在cmd中执行该命令,一般安装完SQL Server后该命令对 ...
- 【Swift 3.1】iOS开发笔记(四)
一.唱片旋转效果(360°无限顺时针旋转) func animationRotateCover() { coverImageView.layer.removeAllAnimations() let a ...
- Python dict和set的实现原理
在python的dict中间进行查找某个key操作时,查找所需时间不会随着dict中键值对数量增多而变长,(时间复杂度为O(1))但是list中就会(时间复杂度为O(N)),这是因为list查询实现的 ...
- Java的selenium代码随笔(3)
/** 以下方法主要用于切换页面*/public void SetPageSwitch(String pageTitle) {Set<String> allWindowsHandles = ...
- 【数学建模】灰色系统理论II-Verhulst建模-GM(1,N)-GM(2,1)建模
灰色系统理论中,GM(1,1)建模很常用,但他是有一定适应范围的. GM(1,1)适合于指数规律较强的序列,只能描述单调变化过程.对于具有一定随机波动性的序列,我们考虑使用Verhulst预测模型,或 ...