0% found this document useful (0 votes)
1 views13 pages

Python Flow Control Functions

The document covers flow control in Python, including decision making with if, elif, and else statements, as well as various types of loops such as for, while, and nested loops. It also discusses functions, their definition, calling, arguments, recursion, and the ability to return multiple values. Overall, it highlights key programming concepts essential for controlling the flow of execution in Python.

Uploaded by

janani saravanan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views13 pages

Python Flow Control Functions

The document covers flow control in Python, including decision making with if, elif, and else statements, as well as various types of loops such as for, while, and nested loops. It also discusses functions, their definition, calling, arguments, recursion, and the ability to return multiple values. Overall, it highlights key programming concepts essential for controlling the flow of execution in Python.

Uploaded by

janani saravanan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Python Programming – Flow

Control & Functions


Decision Making, Loops, and
Functions
By Janani
Flow Control in Python
• Flow control is how a program makes
decisions or repeats tasks.

• Includes:
• • Decision Making
• • Loops
• • Nested Loops
Decision Making
• Python uses if, elif, and else for decisions.

• Example:
• age = 18
• if age >= 18:
• print("Adult")
• else:
• print("Minor")
Types of Loops
• 1. for loop: Used for iterating over a sequence.
• 2. while loop: Repeats while a condition is
True.
• 3. nested loop: Loop inside another loop.
for Loop Example
• for i in range(5):
• print(i)
• # Outputs: 0 to 4
while Loop Example
• count = 0
• while count < 5:
• print(count)
• count += 1
• # Outputs: 0 to 4
Nested Loops
• Used for working with multi-level data.

• Example:
• for i in range(3):
• for j in range(2):
• print(i, j)
Functions in Python
• A function is a block of code that performs a
task.

• Use 'def' to define a function.

• Example:
• def greet():
• print("Hello!")
Function Calling
• After defining a function, you call it using its
name.

• Example:
• def greet():
• print("Hello")

• greet()
Function Arguments
• Functions can accept values (arguments).

• Example:
• def greet(name):
• print("Hello", name)

• greet("Janani")
Recursive Function
• A function that calls itself.

• Example:
• def factorial(n):
• if n == 0:
• return 1
• return n * factorial(n-1)
Multiple Return Values
• A function can return more than one value.

• Example:
• def calc(a, b):
• return a+b, a*b

• sum, prod = calc(2, 3)


• print(sum, prod)
Summary
• • if, elif, else help in decision making
• • Loops: for, while, nested
• • Functions: define, call, pass arguments
• • Recursion and multiple return values are
powerful features

You might also like