This gives the complete idea of function how function works their example

ahmadlodhi25ap 7 views 26 slides Oct 24, 2025
Slide 1
Slide 1 of 26
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15
Slide 16
16
Slide 17
17
Slide 18
18
Slide 19
19
Slide 20
20
Slide 21
21
Slide 22
22
Slide 23
23
Slide 24
24
Slide 25
25
Slide 26
26

About This Presentation

An Ant passed by. On his back, he carried a grain of corn he harvested. He walked with great effort. He needed to take the grain of corn to his home.


Slide Content

Operations on String and Conditional Statement

Operation on String Python provides many built-in string methods for text manipulation Operation Description Example Output upper() Converts all letters to uppercase "hello".upper() HELLO lower() Converts all letters to lowercase "HELLO".lower() hello title() Capitalizes first letter of each word "python programming".title () Python Programming strip() Removes spaces from start & end " hi ".strip() hi replace(a, b) Replaces part of string "good day".replace (" day","night ") good night

Operation on String Strings are immutable — methods return new strings, not modify the original. Operation Description Example Output find(sub) Finds first index of substring, returns -1 if not found " apple".find ("p") 1 index(sub) Like find(), but raises error if not found "apple".index("p") 1 count(sub) count(sub) count(sub) count(sub) startswith(sub) Checks if string starts with substring "hello".startswith("he") True endswith(sub) Checks if string ends with substring "hello".endswith("o") True

Operation on String

What are conditional Statements? Conditional statements in Python allow you to make decisions in your program based on conditions (True/False ). They help control the flow of execution.

Types of Conditional Statements if Statement if...else Statement if... elif ...else Statement Nested if Short Hand if / Ternary Operator Logical Operators with Conditions

if s tatement if op == '+': add(number1, number2) This is a conditional statement. IF statement has following two parts IF statement Body of IF statement Variable Comparison Operator Value Reserved Word

if statement The if statement is used to check a condition. If the condition is True, the code inside it executes . The condition must return True or False. The code under if must be indented (4 spaces ). Nothing happens if the condition is False.

i f Statement

if else statement Used to make decisions in code . Executes different blocks of code based on conditions . Helps your program respond intelligently to different situations . The condition is a logical test (True or False ). The else part is optional Example : If it's raining, take an umbrella. Else, enjoy the sunshine!

if else Statement

if elif else statement i f elif else is used when you have more than two conditions . It helps your program choose one path among many . e lif stands for else if . Example: If it’s hot, wear shorts. Elif it’s cold, wear a jacket. Else, wear normal clothes.

if elif else statement

Nested if Statement A nested if means placing one if statement inside another . It allows your program to make more specific decisions . Think of it like asking a follow-up question when the first answer is true . Example : If it’s raining → check if you have an umbrella → if yes, go outside.

Nested if statement

Shorthand if Statement A shorthand if is used when you want to write an if statement in a single line — perfect for short and simple conditions.

Shorthand if else Statement Use shorthand if an if else for clean and concise code, but avoid it in complex logic for better readability.

Logical Operators Logical operators are used to combine multiple conditions in programming . They allow your code to make complex decisions . Common logical operators in Python : And Or Not Example: If it’s sunny and warm → go for a walk.

And Operator

Or Operator

Not Operator

Problem Stat e ment : University Admission System Write a Python program for a university admission system that: Checks if the student is eligible to apply (based on age and nationality). Displays their grade based on marks. Uses a nested if to decide scholarship eligibility (based on grade and marks). Uses a ternary operator to show Pass or Fail status.

Solution:

Self Assessment Write a Python program that checks a person’s age and salary to decide if they can apply for a car loan. If the person is above 21 and has a salary of at least 30,000, they are eligible. If their salary is above 80,000, they also get a premium loan offer (use nested if). Use a ternary operator to show whether the person is “Approved” or “Rejected”.
Tags