Module 5: Python - Key Features of Coding

| Condition | Iteration | Function |


Slides
Watch Videos on | Condition | Iteration | Function |
Video Lecture

Tipping Points


Conditional Statement


  • if ... else ... statement
  • if ... elif ... else ... statement
  • if  and  :
       
    elif   :
       
    else:
       
    
               

Iteration Statement


  • The basic principle of iteration is to say
    "for each element in a list"
    
    
               
  • a list for the for loop can be
    • the range() function
    • a list
    • a list formed from an external source
        External sources are
      • file
      • web page
      • JSON data
      • etc...
  • while loop can be also used

Functions


  • Functions are defined for zero or more parameters
  • Those functions are called by sending zero or more arguments
  • The parameters of a function should be matched with the arguments of a function caller.
  • Write a Python program to convert Kb to Lb, vice versa.
    • Check out the web, formula
    • Define the mass conversion function, kg2lb() and lb2kg().
      • kg2lb(), which takes a number in kb and returns another number in lb.
      • lb2kg(), which takes a number in lb and returns another number in kg.
    • Call the above functions by sending numbers as follows:
      • kg2lb(67)
      • lb2kg(159)
    • Can you take numbers from user to call those functions?
See how? Click the button "To See More" to go to the right pane!