笨方法python3_“笨方法”学Python3,习题 03 。

125826d7b0c52d9152d918e7d035b23f.png

笨方法”学Python3,习题 03:数字和数字计算

1、数字如何计算?

2、怎么打印数字的计算结果?

一、基础代码

所写的代码:
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)
---------------------------------------------------------------------------------------------------
应该看到的结果:
PS D:代码> & D:/软件/python/python.exe d:/代码/ex3.py
I will now count my chickens:
Hens 30.0
Roosters 97
Now I will count the eggs:
6.75
Is it true that 3 + 2 < 5 - 7?
False
What is 3 + 2? 5
What is 5 - 7? -2
Oh, that's why it's False.
How about some more.
Is it greater? True
Is it greater or equal? True
Is it less or equal? False

92cdfafe997f7579ea1fbd3531c957f8.png

二、巩固练习

1、写注释
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)
2、用Python计算数字(这里在VS Code中计算)

2c60293d8e3f7899eb759264cd90001a.png
直接在输出的地方打字,然后回车就可以输出结果

总结:

1、Python可以用来计算

2、Print里可以判断数字的比较,也可以输出数字计算的结果

3、浮点数更精确,用于需要高度准确的计算上

4、加(+)、减(-)、乘(*)、除(/)、取余(%)。

^ v ^,知乎此系列文章内容均会在微信公众号中同步更新,公众号:小民有个小旮旯

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值