in the lecture:
-
recap last lecture and solved hw2.
-
elif
-
if conditions-operators:
- "and" vs & : & =bitwise AND (working on the number in binary)
- short circuit in "and","or" operators: (condition1 and condition2 )=if the first condition is false, python will not check the other conditions in the if.
- and not balance==100_000 = balance!=100_000
- operators:
- and (&&): a <= 10 >= 12 / a >= 10 and a <= 12
- or (||)
- not (!=)
- is (==)
- match-case:
- match day=switch day
- without break-because the indentation
- case _: = default:
- merge cases: case 10 | 11| 12
- case _ if 0 <= grade <= 40
-
print format: https://docs.python.org/3/tutorial/inputoutput.html
"your name is {x}, your age is {y}."
print( **f**"your name is {x}, your age is {y}.")
-
to print only 2 digits after the '.':
print(f"Pi:{pi:.2f}")
-
to align the string:
- to the left <:add 20 spaces characters and align text to the left
print(f"Name: {name1:<20} {age1}")
- to the right >: add 20 spaces characters and align text to the right
print(f"Name: {name1:>20} {age1}")
- to the center ^: add 20 spaces characters and align text to the center (between the spaces
print(f"Name: {name1:^20} {age1}")
- number to percentage: 0.5 to 50%:
print(f"{prec:%}")
- percentage with 2 digits after the '.':
print(f"percentage 2 digits after the .: {perc:.2%}")