Python Essentials Classroom Series – 04/Sept/2021

Conditionals using python continued

  • Now lets look at python comparison operators
Description operator
equality ==
inequality !=
less than <
less than or equals <=
greater than >
greater than or equals >=
  • Sample usage Preview
  • Lets write a simple program which will take input from user a number and identifies if the number is even or odd
number = int(input('Enter the number: '))

if number <= 0:
    print("number is neither even nor odd. trying giving positive non zero numbers")
    if number%2 == 0:
  • write a program to accept the marks of maths, physics and chemistry and try to determine grades (A1, A2, B1, B2, C)
maths = int(input("Enter the marks in maths: "))
physics = int(input("Enter the marks in physics: "))
chemistry = int(input("Enter the marks in chemistry: "))
average = (maths + physics + chemistry) / 3
if 92 <= average <= 100 :
elif 83 <= average <= 91:
elif 75 <= average <= 82:
elif 67 <= average <= 74:

Text Strings

  • In python any value enclosed in single or double quotes or triple quotes is a string Preview Preview
  • Triple quotes are useful for multi line strings Preview Preview
  • Create with str(): We can create a string from other data type using str() function Preview
  • Escape sequence Preview Preview

Combining by using + and Duplication with *

  • In python you can combine literal strings or string variables using the + operator Preview Preview

Leave a Comment

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

About learningthoughtsadmin