0% found this document useful (0 votes)
27 views5 pages

CSE Lab - Report 3

The document describes a Python program to find the largest number in a list using a for loop. It provides the objectives, description of for loops in Python, example source code, an output screenshot, and conclusion on using for loops to iterate through lists and find the maximum value.
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)
27 views5 pages

CSE Lab - Report 3

The document describes a Python program to find the largest number in a list using a for loop. It provides the objectives, description of for loops in Python, example source code, an output screenshot, and conclusion on using for loops to iterate through lists and find the maximum value.
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
You are on page 1/ 5

CHITTAGONG UNIVERSITY OF

ENGINEERING AND TECHNOLOGY

Department of Urban and Regional Planning


Course Name: Programming for Planners
Course ID: CSE 282

Experiment
Experiment Title
No.

Write a Python program to get the largest


03
number from a list.

Name: Norin Binte Khorshed Megha


Student ID: 2005028
Level: 2
Term: II
Date of Submission: 18th September, 2023
1. Objectives:

 To learn about data structure list in python.


 To learn about list functions like -Append, remove, insert, pop, clear, index, sort,
reverse, count, len etc.
 To learn about loops in python like -while loop, for loop.

2. Description:

In a programming language, a loop allows you to run a statement—or a group of statements—


more than once based on the outcome of the condition that needs to be assessed in order to
execute the statement. For statements inside of loops to be executed, the outcome condition
must be true. The for loop turns complicated issues into straightforward ones. It allows us to
modify the program's flow so that we can only repeat comparable code a finite amount of times
rather than writing the same code repeatedly.

Syntax of for Loop:

for value in sequence:

{loop body}

1
A for loop is used for iterating over a sequence (that is either a list, a tuple, a dictionary, a set,
or a string). This is less like the for keyword in other programming languages, and works more
like an iterator method as found in other object-orientated programming languages. Because
the "range" function appears so frequently in for loops, we might mistakenly believe the range
is a component of the syntax of for loop. It isn't: it's a Python built-in method that provides a
series that follows a specified pattern (usually serial integers), fulfilling the criteria of giving a
series for the for expression to run over. There is no necessity to count because for can act
straight on sequences most of the time. On the other side, the if condition is considered the
simplest of the three and makes a decision based on whether the condition is true or not. If the
condition is true, it prints out the indented expression. If the condition is false, it skips printing
the indented expression.

3. Source Code:

For source code, we need to take X as an integer number where any value can be given.

Now we will type the code using loop.

X= [10,11,12,13,14,15] →Taking a list named X.

max=0 → Taking the maximum number as max.

a=len(X) →Taking a as the loop and it will be looping depending on

the number of c.

for i in range(a): →Looping in respect of a.

if(X[i]>m): →Taking condition.

m=X[i]

print(m) →Output of the largest number

There I have given the screenshot of the code from the computer.

2
4. Output Screenshot:

The output will come with the largest number. It will calculate all the values that has

been listed.

5. Conclusion:

In Python, the for loop is often used to iterate over iterable objects such as lists, tuples, or
strings. After clicking run, the largest number will be shown. The for loop in Python is very
similar to other programming languages. We can use break and continue statements with for
loop to alter the execution. However, in Python, we can have optional else block in for loop
too. There a coder should incorporate with some challenges like: -

3
 It is important to follow some basic rules of coding like using brackets, using inverted
coma (“”) in appropriate place, using numeric and string values perfectly.
 The length should not be normally more than 8 characters.
 White spaces should be avoided.
 While doing the code, I was not able to understand the len(c) code for what it has been
used.

-------------------------------------------------------------------------------------------------------------

You might also like