[Go to site: main page, start]

0% found this document useful (0 votes)
6 views26 pages

Python Loops and String Manipulation Guide

Uploaded by

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

Python Loops and String Manipulation Guide

Uploaded by

carmenlight123
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

PYTHON

SECTION 3
Agenda
Loops

Nested Loops

Strings Manipulation
LOOPS
“FOR LOOP” SYNTAX

◾ A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set, or a string).

◾ With the for loop, we can execute a set of statements, once for each item in Sequence (range , list, tuple, etc).
THE RANGE() FUNCTION
THE RANGE() FUNCTION
“FOR LOOP”

◾ Example: python program to print odd number in range (1,20)


“FOR LOOP”

◾ Example: python program to print sum of numbers from 1 to 11


“WHILE LOOP” SYNTAX
Repeated the code
as long as condition
is true.

Loop needs to contain initialize point , condition and updated point.


EX
Write a python program to check if the password entered by
user is correct ( 3 trials are allowed )
NESTED LOOP
◾ Syntax of using a nested for loop in Python
NESTED LOOP
Write program to print multiplication table in Python.
NESTED LOOP
Write program to Print Pattern

*
**
***
STRING DATA IN PYTHON
STRING MANIPULATION
STRING DATA IN PYTHON
STRING MANIPULATION
STRING DATA IN PYTHON
STRING MANIPULATION
▪ Task 1 : Write a Python program to calculate the sum squared numbers
from 1 to n.

▪ Task 2: Write a program that counts the number of vowels in a given


string.

▪ Task 3: Write a program that calculates the factorial of a given number

Note: only loops and if conditions are allowed to use.


THANK YOU

You might also like