Python Essentials Classroom Series – 10/Jul/2021

Conditionals and Control Flow

  • Conditionals execute certain block (line or lines of code) depending on some condition
    • if-else:
      number = 11
      remainder = number % 2
      print(remainder)
      if remainder == 0:
          print('even')
      else:
          print('odd')
      
    • if-elif-else:
      total_marks = 600
      acheived_marks = 544
      average = (acheived_marks/total_marks) * 100
      
      if 90 <  average <= 100:
          print('A1')
      elif 80 <= average <= 90:
          print('A2')
      elif 70 <= average <= 80:
          print('B1')
      elif 60 <= average <= 70:
          print('B2')
      elif 50 <= average <= 60:
          print('C1')
      elif 40 <= average <= 50:
          print('C2')
      elif 32 <= average <= 40:
          print('D')
      elif 20 <= average <= 32:
          print('E1')
      elif 0 <= average <= 20:
          print('E2')
      else:
          print('average should in range of 0-100')
      
      
      • Exercise: Write a python program using if elif statements to findout the largest number among a b c
      a = 10
      b = 5
      c = 11
      
      print c is greater
      

Operator Precedence

  • The below table defines operator precedence Preview

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About learningthoughtsadmin