Python Classroom notes 22/Sep/2026

Conditionals

  • Options:

    • if
    • if else
    • if elif .. else
  • syntax

if <condition>:
   ...
   ...
   ...
  • example
x = 2

if x > 4:
    x = x + 1
    print(x)
print("completed")
  • syntax
if <condition>:
    ....
    ....
else:
    ....
    ....
  • sample
x = 20

if x > 4:
    x = x + 1
    print(x)
else:
    x = x - 1
    print(x)
print("completed")
  • When we have more that two conditions
if <condition>:
   ....
   ....
elif <condition>:
   ....
   ....
elif <condition>:
   ....
   ....
else:
   ....
   ....

  • Example
average = 5
if average >= 80:
    print("Grade A")
elif 60 <= average < 80:
    print("Grade B")
else:
    print("Grade C")
print("Grading Completed.")
  • sequence of if statements
average = 85
if average >= 80:
    print("Grade A")
if  60 <= average < 80:
    print("Grade B")
if average < 60:
    print("Grade C")
print("Grading completed.")

#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    n = int(input().strip())
    if n%2 != 0:
        print("Weird")
    else:
        if 2 <= n <= 5:
            print("Not Weird")
        elif 6 <= n <= 20:
            print("Weird")
        else:
            print("Not Weird")


  • optimized version
#!/bin/python3

import math
import os
import random
import re
import sys



if __name__ == '__main__':
    n = int(input().strip())
    if n%2 != 0 or 6 <= n <= 20:
        print("Weird")
    else:
        print("Not Weird")


  • Exercise – 1:
    • Take six subject marks as inputs
    • Calculate Average
    • Give me grades according to CBSE Grading.
  • Exercise – 2:
    • Take a salary and calculate income tax

By continuous learner

enthusiastic technology learner

Leave a Reply

Discover more from Direct AI Powered By Quality Thought

Subscribe now to keep reading and get access to the full archive.

Continue reading