Lab 05
Lab 05
Lab #5
Dr Asad Mansoor Khan
LE Kashaf Raheem
QUIZ 3
EVEN SEAT ODD SEAT
Write a Python Write a Python
program to display program to display
all numbers all numbers
between 100 and between 100 and
250 where the 250 where the sum
product of their of their digits is
digits is greater greater than 10.
than 10.
2
Algorithms and
Repetition
Aim
Exploring python syntax and problem-solving w.r.t repetition
structures
3
Python Syntax
for and more
4
Range Function
• Creates a list of integer values usually used to
iterate in a for loop
6
Range function
• range(a, b, c)
a = Starting value, default value is 0
b = Terminating condition, must always
be given
c = Increment/decrement, default value
is +1
7
Example:
Question Solution
10
Example:
Question Solution
Write a
original_str = input("Enter a string to
be revered: ")
rev_str = ""
reverses a for i in range(1, Len+1):
string entered i]
rev_str = rev_str + original_str[Len -
11
Tasks
Make sure to comment your code.
Use appropriate variable name
Know the location where file is being saved
Create different files for different tasks
14
Task 1:
a) Write a program in python that gets
a string from user and checks whether
the user entered data is a palindrome
or not. E.g.,
User enters: LEVEL, It is a palindrome as Reverse of
this remains LEVEL
User enters: 12344321, It is a palindrome as Reverse
of this remains 12344321
b) Edit the code such that it re-runs until
user enters No or Quit
15
Note: The characters are
arranged in descending
Task 2: order
𝑛! = ෑ 𝑖
𝑖=1
17
Next week: Python
Syntax and Problem
Solving!
Advice:
Explore Leetcode for problem solving!
19