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

CSE Lab-Report 4

The document describes an experiment to find the minimum value in a tuple using Python. It defines a tuple called c with values (10, 20, 30, 40, 50). A for loop iterates through the tuple, tracking the minimum value in a variable called min. If a value in the tuple is less than the current min, it updates min to that value. After the loop, min will hold the smallest number from the tuple. The output screenshot shows min is correctly printed as 10, the minimum 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)
21 views5 pages

CSE Lab-Report 4

The document describes an experiment to find the minimum value in a tuple using Python. It defines a tuple called c with values (10, 20, 30, 40, 50). A for loop iterates through the tuple, tracking the minimum value in a variable called min. If a value in the tuple is less than the current min, it updates min to that value. After the loop, min will hold the smallest number from the tuple. The output screenshot shows min is correctly printed as 10, the minimum 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.

04 Find the minimum value of tuple.

Name: Norin Binte Khorshed Megha


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

 To learn about tuples and its functions.


 To learn about loops in python like -while loop, for loop.

2. Description:

A Python Tuple is a group of objects with commas between them. A tuple is somewhat akin
to a list in terms of indexing, nested items, and repetition, however a tuple is immutable as
opposed to mutable lists. There are some operations for accessing Values in Python Tuples:

 Using Positive Index: Using square brackets we can get the values from tuples in
Python.
 Using Negative Index: In the above methods, we use the positive index to access the
value in Python, and here we will use -ve index within.
 Concatenation of Python Tuples: To concatenate the Python tuple we will use plus
operators (+).
 Nesting of Python Tuples: In python, we can have nested tuples as well. This refers
to the structure that has a tuple as a data item of another outer tuple. The normal rules
of tuples in python apply to this concept as well.
 Repetition Python Tuples: To repeat a tuple in Python, we use the asterisk operator”
*” The asterisk. is used to repeat a tuple n (number) of times. Which is given by the
integer value” n” and creates a new tuple value.
 Immutable Python Tuples: Tuples are immutable, meaning that once a tuple has been
created, the items in it can’t change.
 Slicing Python Tuples: Slicing operator can be used with any sequence data type,
including Tuple. Slicing means separating a part of a sequence, here a tuple.
 Deleting a Tuple: Tuples are immutable and cannot be deleted. You cannot delete or
remove items from a tuple. But deleting tuple entirely is possible by using the keyword
del.

1
 Finding Length of a Tuple: Finding the size or length of a tuple is a pretty
straightforward process. The size of a tuple represents the number of objects present in
the tuple. The syntax used for finding the size is len (). This method returns the number
of elements/objects present in the tuple.
 Converting list to a Tuple: The tuple () function is the easiest way to convert a list
into a tuple value.
 Tuples in a loop: Tuples are ordered, indexed collections of data. Similar to string
indices, the first value in the tuple will have the index, the second value, and so
on.Tuples can store duplicate values. Once data is assigned to a tuple, the values cannot
be changed. Tuples allow you to store several data items in one variable.

On the other hand, using a loop in a programming language allows one 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 for the statements to be executed. For statements inside of loops to be
executed, the outcome condition must be true. The for loop turns complicated issues into
straightforward ones.

3. Source Code:

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

Now we will type the code.

c= (10,20,30,40,50) →Taking a tupple named c.

min=10000 → Taking minimum number as min.

a=len(c) →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(c[i]<min): →Taking condition.

min=c[i]

print(min) →Output of the minimum number

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

4. Output Screenshot:

The output will come with the minimum number. It will calculate all the values that has been
listed.

5. Conclusion:

In computer programming, tuples provide an efficient way to store multiple values. Since they
are static and cannot be modified, tuples generally require less memory than arrays. 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