数字和数学计算
+,-,
/,斜杠,除
%,百分号,余数
<,>,<=,>=
下文是整数型录入的,浮点型更准确。以下案例体现在哪里,取余数试试
print("I will now count my chichens:")#纯字符串输入
print("Hens",25+30/6)#字符串加引号,然后逗号-实际是分隔符,没有打印出来,再输入计算公式。计算公式除号优先
print("Roosters",100-25*3%4)#利用了*乘号 和%取余数
print("浮点型",100.00-25.00*3.00%4.00)
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)#计算公式两端不加引号。<>大于小于号的优先级最低,结果是true false
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)
——————————————————————————————————————————————————
执行结果
I will now count my chichens:
Hens 30.0
Roosters 97
浮点型 97.0
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