Sunday, May 17, 2026

Python Material - Part - 9 -Conditional -statement

 __author__ = "Narendra Boyina"

# -----------------------------------------------------------------------------
# Copyright (c) 2025 BR Technologies PVT LTD
#-----------------------------------------------------------------------------
"""
Topics to be covered in today's class:

--> Python's in built functions
int() float() str() list() tuple() dict() set() char() ord() enumerate() min() max() all() any() \
input() print() pow() len() range() map() filter() open() help() id() type() zip() dir() next() \
sorted() sum() hasattr() getattr() setattr() delattr() isinstance() issubclass() super()"""

"""
A conditional statement tells a program to execute a specific block of code based on whether a condition is true or false

1. Introduction to Simple if (if condition with and operator)
2. Nested if
3. If-Else Statements
4. If-Elif-Else Statements
5. Nested if else
6. Using Logical Operators (and, or)
7. Advanced If-Else Usage
8. assert"""
"""
syntax:

if condition is True:
this statement/ statements will execute
"""
# num = input("Enter any number: ") # by-default input() method consider as string (if user provides integer also )
# print(num, type(num))
# num = int(input("Enter any number: ")) # taking input from user
# print(num, type(num))
# if num < 10:
# print("given number less than 10")
# print("{} is less than 10".format(num))
# print("ganesh")
# print("Narendra")
# print("Pramodh")

"""Nested if """
# number = int(input("Enter any number"))
# if number%5 == 0:
# if number%7 == 0:
# print(number, "is divisible by 5 and 7")
#
# print("Narendra")



""" above program can be simplified by using logical and operator """
# number = int(input("Enter any number"))
# # number = 30
# if number % 5 == 0 and number % 7 == 0:
# print(number, "is divisible by 5 and 7")
# print("44444444444444444")
# print("Narendra")

"""
# Introduction to If-Else Conditions
# ----------------------------------------------
# The if-else statement is used to execute code based on a condition.
# If the condition is true,the code inside the if block is executed.
# If the condition is false, the code inside the else block is executed.

if else Syntax:
==============
if expression:
statement(s)
else:
statement(s)
"""
# Narendra = int(input("Enter any number: "))
# if Narendra < 10:
# print("{} is less than 10".format(Narendra))
#
# else:
# print("{} is greater than 10".format(Narendra))
# print("$$$$$$$$$$$$$$$$$$$$$$$$$$$$")
#
# print("Mahalakshmi")

"""
Nested if else Syntax:
==============
if expression:
if expression:
statement(s)
else:
statement(s)
else:
statement(s)
"""
""" Example : Simple Authentication Check """

sign_up_user = "radhika_kruthika"
sign_up_pass = "Kr@24!&#" # assume both values stored in DB

sign_in_user = "radhika_kruthika"
sign_in_pass = "Kr@24!&#"

# if sign_in_user == sign_up_user:
# if sign_in_pass == sign_up_pass:
# print("valid user: Show the content")
# else:
# print("username is valid, but password is not correct, would like to reset")
# else:
# print("not valid user: check username")
#
# if sign_in_user == sign_up_user and sign_in_pass == sign_up_pass:
# print("valid user: Show the content")
# else:
# print("not valid user: check username or password may be wrong")
"""

if elif else Syntax (Ladder elif):
===============================

if expression1:
statement(s)
elif expression2:
statement(s)
elif expression3:
statement(s)
elif expression4:
statement(s)
else:
statement(s)

Note: for this syntax, I will explain with real time example in next file

"""
# x = int(input("Enter any number: ")) # 370
# if x <= 100:
# print("{0} is less than 100".format(x))
# print("Narendra")
# elif x >100 and x <= 200:
# print("{} is less than 200 more than 100".format(x))
# elif x > 200 and x <= 300:
# print("{} is less than 300 more than 200".format(x))
# elif x > 300 and x <= 400:
# print("{} is less than 400 more than 300".format(x))
# else:
# print("{} is more than 400 ".format(x))
#
# print("Subramanyam")


"""
concept usage: Loan Eligibility Checker
Description: Check if a person is eligible for a loan based on age and income """

# age = int(input("Enter your age: "))
# income = float(input("Enter your monthly income: "))
# cbil_score = int(input("Enter your cbil_score: "))

# Example for if else
# if age >= 21 and age <= 60 and income >= 30000 and cbil_score >= 700:
# print("You are eligible for the loan")
# else:
# print("You are not eligible for the loan")


#example for Nested if else
# if age >= 21 and age <= 60:
# if income >= 30000 and cbil_score >= 700:
# print("You are eligible for the loan")
# else:
# print("You are not eligible for the loan due to salary or Cibil score")
# else:
# print("You are not eligible for the loan due to age")

"""
Ternary operator
How can the ternary operators be used in python?

Ans: The Ternary operator is used to show the conditional statements.
This consists of the true or false values with a statement that has to be evaluated for it.

Syntax:

The Ternary operator will be given as:
[on_true] if [expression] else [on_false]

Result = x if x > y else y

Example: The expression gets evaluated like if x>y else y, in this case if x>y is true
then the value is returned as big=x and if it is incorrect then big=y will be sent as a result.
"""
# x, y = 1135, 150
# big = x if x > y else y # 135 >150
# print(big)


"""
The assert keyword is used when debugging code.
The assert keyword allows you to check if a condition in your code is True;
If condition false, the program will raise an AssertionError.
You can also provide a message that will be displayed if the assertion fails, as shown in the example below.
"""


# name = input("Enter name:")
# if name == "Narendra":
# print("given right information")

# name = input("Enter name:")
#
# if condition returns False, AssertionError is raised:
# assert name == "Narendra", "name should be 'Narendra'"
# print("given right information")

===================================================================================
                                Example
===================================================================================

__author__ = "Narendra Boyina"
# Small program dedicated to my 1st batch students in BR techno solutions

# Function declaration / function definition
def Salary(EmpId, Expe, sal, Level, Rating):

if (Expe == 1 and Level == "c1" and Rating == "superstar"):
print(EmpId, " Hike is 25%,Salary after increment", ((.25 * sal) + sal))
elif (Expe == 1 and Level == "c1" and Rating == "star"):
print(EmpId," Hike is 20%,Salary after increment", ((.20 * sal) + sal))
elif (Expe == 1 and Level == "c1" and Rating == "pillor"):
print(EmpId," Hike is 15%,Salary after increment", ((.15 * sal) + sal))
elif (Expe == 1 and Level == "c1" and Rating == "below expectations"):
print(EmpId," Hike is 9%,Salary after increment", ((.10 * sal) + sal))
elif(Expe == 1 and Level=="c1" and Rating=="nominal"):
print(EmpId,'Hike is 3%,salary after increment',((.03*sal)+sal))

elif (Expe == (2 or 3) and Level == "c2" and Rating == "superstar"):
print(EmpId," Hike is 18%,Salary after increment", ((.18 * sal) + sal))
elif (Expe == (2 or 3) and Level == "c2" and Rating == "star"):
print(EmpId," Hike is 15%,Salary after increment", ((.15 * sal) + sal))
elif (Expe == (2 or 3) and Level == "c2" and Rating == "pillor"):
print(" Hike is 10%,Salary after increment", ((.10 * sal) + sal))
elif (Expe == (2 or 3) and Level == "c2" and Rating == "below expectations"):
print(" Hike is 8%,Salary after increment", ((.08 * sal) + sal))

elif (Expe == (4 or 5 or 6) and Level == "c3" and Rating == "superstar"):
print(" Hike is 15%,Salary after increment", ((.15 * sal) + sal))
elif (Expe == (4 or 5 or 6) and Level == "c3" and Rating == "star"):
print("Hike is 12%,Salary after increment", ((.12 * sal) + sal))
elif (Expe == (4 or 5 or 6) and Level == "c3" and Rating == "pillor"):
print(" Hike is 8%,Salary after increment", ((.08 * sal) + sal))
elif (Expe == (4 or 5 or 6) and Level == "c3" and Rating == "below expectations"):
print(" Hike is 6%,Salary after increment", ((.06 * sal) + sal))

elif (Expe == (7 or 8 or 9) and Level == ("c4" or "c5") and Rating == "superstar"):
print(" Hike is 13%,Salary after increment", ((.13 * sal) + sal))
elif (Expe == (7 or 8 or 9) and Level == ("c4" or "c5") and Rating == "star"):
print(" Hike is 9%,Salary after increment", ((.09 * sal) + sal))
elif (Expe == (7 or 8 or 9) and Level == ("c4" or "c5") and Rating == "pillor"):
print(" Hike is 7%,Salary after increment", ((.07 * sal) + sal))
elif (Expe == (7 or 8 or 9) and Level == ("c4" or "c5") and Rating == "below expectations"):
print(" Hike is 5%,Salary after increment", ((.05 * sal) + sal))

elif (Expe >= 10 and Level == ("c6" or "c7") and Rating == "superstar"):
print(" Hike is 10%,Salary after increment", ((.10 * sal) + sal))
elif (Expe >= 10 and Level == ("c6" or "c7") and Rating == "star"):
print(" Hike is 7%,Salary after increment", ((.07 * sal) + sal))
elif (Expe >= 10 and Level == ("c6" or "c7") and Rating == "pillor"):
print(" Hike is 5%,Salary after increment", ((.05 * sal) + sal))
elif Expe >= 10 and Level == ("c6" or "c7") and Rating == "below expectations":
print(" Hike is 3%,Salary after increment", ((.03 * sal) + sal))
else:
print("given values are not match")

# a = int(input("Enter employee Exp :"))
# b = int(input("Enter employee Salary :"))


# Salary("HM0002162", 2, 25000, "c2", "star") # calling function
Salary("HM0002162", 7, 92000, "c2", "star")

Author: Boyina Narendra

Supporting Author: M. Meera Sindhu

Request: If you find this information useful, please provide your valuable comments

No comments:

Post a Comment