- Mathematical operation in python
string can't be converted to int need to be float() first - Number manupulation and f string in python
- Round the number
use round( )
round to different desimal placesround(8/3,3)
- Use floor divison---
// to be an integer8//3 type(8//3)
/ to be a float - f string
score=0
print("your score is "+str(score))
#f-String
in front of the double quote / single quoteuse print() below to check your code!
- 2.0但我仍然要两位数👇
Using str.format()'s syntax to display answer
with two decimal places (without altering the underlying value of answer
):
def printC(answer):
print("\nYour Celsius value is {:0.2f}ºC.\n".format(answer))
Where:
:
introduces the format spec0
enables sign-aware zero-padding for numeric types.2
sets the precision to2
f
displays the number as a fixed-point number- Condition statement
water_level = 50 if water_level > 80: print("Drain water") else: print("Continue")
Comparison Operators
-
== check if the value on the left is equal to the right
-
= means that you're assigning this value(right) to this valuable(left)
-
!=
- Modulo Operation
7%2
1
- Nested if /else
if condition:
if another condition :
do this
else:
do this
else :
do this
- elif statement
- Multiple if statements