码迷,mamicode.com
首页 > 编程语言 > 详细

python编辑基础与http接口测试_5.1章节

时间:2018-04-18 20:12:45      阅读:162      评论:0      收藏:0      [点我收藏+]

标签:数字   选择   ==   orm   error   pre   python   error:   数值   

题目:运行程序,提示‘选择运算符’,输入‘1/2/3/4’ 之一并回车后,继续输入要运算的两个数字后回车,打印出该运算结果,如下图

技术分享图片

 1 #感谢本书作者阿奎老师
 2 import Calculator
 3 cal=Calculator.Calculator()
 4 x=input(选择运算符:\n1 is +\n2 is -\n3 is *\n4 is /\n输入你的选择:)
 5 if x not in [1, 2, 3, 4]:
 6     print(输入运算符错误)
 7 else:
 8     try:
 9         a = float(input(输入第一个数值))
10         b = float(input(输入第二个数值))
11         if x == 1:
12             print({}和{}之和等于{}.format(a, b, cal.add(a, b)))
13         elif x == 2:
14             print({}和{}之差等于{}.format(a, b, cal.minus(a, b)))
15         elif x == 3:
16             print({}和{}之积等于{}.format(a, b, cal.multiply(a, b)))
17         else:
18             print({}和{}之除等于{}.format(a, b, cal.divide(a, b)))
19     except ValueError:
20         print(输入非数字)
21          
22             

 

python编辑基础与http接口测试_5.1章节

标签:数字   选择   ==   orm   error   pre   python   error:   数值   

原文地址:https://www.cnblogs.com/jiawenliao/p/8877103.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!