笨方法”学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
二、巩固练习
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中计算)
总结:
1、Python可以用来计算
2、Print里可以判断数字的比较,也可以输出数字计算的结果
3、浮点数更精确,用于需要高度准确的计算上
4、加(+)、减(-)、乘(*)、除(/)、取余(%)。
^ v ^,知乎此系列文章内容均会在微信公众号中同步更新,公众号:小民有个小旮旯