Skip to content

if, elif, condition operations, matchCase, print format (:.2f=2 digits, :<20, :>20, :^20 =padding stick to the left, right, center, :% =number to percentage )

Notifications You must be signed in to change notification settings

ShaniStaretz-ai/python-lec3-sep-04-24

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

python-lec3-sep-04-24

in the lecture:

  1. recap last lecture and solved hw2.

  2. elif

  3. if conditions-operators:

    1. "and" vs & : & =bitwise AND (working on the number in binary)
    2. 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.
    3. and not balance==100_000 = balance!=100_000
    4. operators:
      1. and (&&): a <= 10 >= 12 / a >= 10 and a <= 12
      2. or (||)
      3. not (!=)
      4. is (==)
    5. match-case:
      1. match day=switch day
      2. without break-because the indentation
      3. case _: = default:
      4. merge cases: case 10 | 11| 12
      5. case _ if 0 <= grade <= 40
  4. 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}.")

options:

  1. to print only 2 digits after the '.':

      print(f"Pi:{pi:.2f}")
    
  2. to align the string:

    1. to the left <:add 20 spaces characters and align text to the left
        print(f"Name: {name1:<20} {age1}")
    
    1. to the right >: add 20 spaces characters and align text to the right
    print(f"Name: {name1:>20} {age1}")
    
    1. to the center ^: add 20 spaces characters and align text to the center (between the spaces
    print(f"Name: {name1:^20} {age1}")
    
    1. number to percentage: 0.5 to 50%:
      print(f"{prec:%}")
      
    2. percentage with 2 digits after the '.':
    print(f"percentage 2 digits after the .: {perc:.2%}")
    

About

if, elif, condition operations, matchCase, print format (:.2f=2 digits, :<20, :>20, :^20 =padding stick to the left, right, center, :% =number to percentage )

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages