• 欢迎访问我的个人博客网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站。
  • 如果您觉得本站对您有用,那么赶紧使用Ctrl+D收藏吧!
  • 相关内容持续完善中......

笨办法学python-习题3:数字和数学计算

Python hubin 1年前 (2018-02-07) 305次浏览 0个评论 扫描二维码

笨办法学python-习题3:数字和数学计算

练习:
print “I will now count my chickens:”
print “Hens”,25 + 30 / 6
print “Roosters”,100 – 25 * 3 % 4
print “Now I will count the eggs:”
print 3 + 2 + 1 – 5 + 4 % 2 – 1 / 4 + 6
print “Is it true that 3+2<5-7?”
print 3 + 2 < 5 – 7
print “what is 3 + 2?”,3+2
print “what is 5 – 7?”,5 – 7
print “Oh,that’s why it’s false.”
print “How about some more.”
print “Is it greater?”,5 > -2
print “Is it greater or equal?”,5 >= -2
print “Is it less or equal?”,5 <= -2

习题:
1.使用#在代码每一行的前一行为自己写一个注释,说明一下这一行的作用。
#打印“I will now count my chickens:”
print “I will now count my chickens:”
#打印”Hens“,计算25+30/6
print “Hens”,25 + 30 / 6
#打印“Roosters”,计算100-25*3%4
print “Roosters”,100 – 25 * 3 % 4
#打印“Now I will count the eggs:”
print “Now I will count the eggs:”
#计算3+2+1-5+4%2-1/4+6
print 3 + 2 + 1 – 5 + 4 % 2 – 1 / 4 + 6
#打印“Is it true that 3+2<5-7?”
print “Is it true that 3+2<5-7?”
#计算3+2<5-7
print 3 + 2 < 5 – 7
#打印“what is 3 + 2?”计算3+2
print “what is 3 + 2?”,3+2
#打印“what is 5 – 7?“,计算5-7
print “what is 5 – 7?”,5 – 7
#打印“what is 5 – 7?”
print “what is 5 – 7?”
#打印“How about some more.”
print “How about some more.”
#打印“Is it greater?”计算5>-2
print “Is it greater?”,5 > -2
#打印“Is it greater or equal?”计算5>=-2
print “Is it greater or equal?”,5 >= -2
#打印”Is it less or equal?”计算5<=-2
print “Is it less or equal?”,5 <= -2
2.使用浮点数重写一遍ex3.py,让它的计算结果更精确(提示:20.0是一个浮点数)
print “I will now count my chickens:”
print “Hens”,25.0 + 30 / 7.0
print “Roosters”,100 – float(25) / 3 % 4
print “Now I will count the eggs:”
print 3 + 2 + 1 – 5 + 4.0 % 2 – 1 / 4 + 6
print “Is it true that 3+2<5-7?”
print 3 + 2 < 5.0 – 7
print “what is 3 + 2?”,3.0+2
print “what is 5 – 7?”,5.0 – 7
print “Oh,that’s why it’s false.”
print “How about some more.”
print “Is it greater?”,5.0 > -2
print “Is it greater or equal>?”,5.0 >= -2
print “Is it less or equal?”,5 <= -2.0
只要操作数之一是浮点型即可,floa(5/3) floa(5)/3 5.0/3 5/3.0 后三个的效果一样都是浮到小数点后10位,float(5/3),先整除之后强行再浮点,没有实际作用。


本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:笨办法学python-习题3:数字和数学计算
喜欢 (0)
hubin
关于作者:
头像
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址