python习题教程 全50个 (不定时更新)EP3

习题3:数字和数学计算

程序代码:

print("I will now count my chickens.")

print("Hens", 25 + 30 / 6)
print("Rooster", 100 - 25 * 3 % 4)
#注意,算式不能被“ ”括住

print("Now I will count the eggs:")

print(3 + 2 + 1 - 5 + 4 % 2 - 1 / 4 + 6)

print("Is it ture 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 greather or equai?", 5>= -2)
print("Is it less or equai?", 5 <= -2)

应该看到的结果:
I will now count my chickens.
Hens 30.0
Rooster 97
Now I will count the eggs:
6.75
Is it ture 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 greather or equai? True
Is it less or equai? False

巩固练习:
1.用浮点数重写ex3.py 提示:20.0就是一个浮点数。

代码总结:

print{用于打印(“”)里的内容}

%的工作方法:

X除以Y的余数是J,%运算的结果就是“Y”

你可能感兴趣的:(python习题教程 全50个 (不定时更新)EP3)