0% found this document useful (0 votes)
3 views

Exp-1 Python

The document outlines an experiment aimed at implementing a Python program to find the sum of natural numbers using a while loop. It includes prerequisites, outcomes, and theoretical explanations of loop types and control statements in Python. Additionally, it provides a section for students to document their observations, conclusions, and further programming exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Exp-1 Python

The document outlines an experiment aimed at implementing a Python program to find the sum of natural numbers using a while loop. It includes prerequisites, outcomes, and theoretical explanations of loop types and control statements in Python. Additionally, it provides a section for students to document their observations, conclusions, and further programming exercises.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

PART A

(PART A : TO BE REFFERED BY STUDENTS)

Experiment No.01
A.1 Aim:
To implement Python Program to Find the Sum of Natural Numbers using while loop.

A.2 Prerequisite:
1. python basics and control structures

A.3 Outcome:
After successful completion of this experiment students will
be able to

To demonstrate basic concepts in python looping.

A.4 Theory& Procedure:


A loop statement allows us to execute a statement or group of statements multiple times. The
following diagram illustrates a loop statement
Sr.No Loop Type & Description
.

1 while loop

Repeats a statement or group of statements while a given condition is TRUE. It


tests the condition before executing the loop body.

2 for loop

Executes a sequence of statements multiple times and abbreviates the code that
manages the loop variable.

3 nested loops

You can use one or more loop inside any another while, for or do..while loop.

Sr.No Control Statement & Description


.

1 break statement

Terminates the loop statement and transfers execution to the statement


immediately following the loop.

2 continue statement

Causes the loop to skip the remainder of its body and immediately retest its
condition prior to reiterating.

3 pass statement

The pass statement in Python is used when a statement is required syntactically


but you do not want any command or code to execute.

FOR LOOP -
For loops are used for sequential traversal. For example: traversing a list or
string or array etc. In Python, there is no C style for loop, i.e., for (i=0; i<n; i++).
There is “for in” loop which is similar to for each loop in other languages. Let us
learn how to use for in loop for sequential traversals.
Syntax:

for var in iterable:


# statements
Here the iterable is a collection of objects like list, tuple. The indented statements
inside the for loops are executed once for each item in an iterable. The variable
var takes the value of next item of the iterable each time through the loop.

While Loops is used to execute a block of statements repeatedly until a given


condition is satisfied. And when the condition becomes false, the line
immediately after the loop in the program is executed. While loop falls under the
category of indefinite iteration. Indefinite iteration means that the number of
times the loop is executed isn’t specified explicitly in advance.

Syntax:
while expression:
statement(s)

PART B
(PART B : TO BE COMPLETED BY STUDENTS)
(Students must submit the soft copy as per following segments within two
hours of the practical. The soft copy must be uploaded on the Blackboard
or emailed to the concerned lab in charge faculties at the end of the
practical in case the there is no Black board access available)

Roll No.: 33 Name: Ashish Bhosale

Class :C Batch :C2

Date of Experiment: Date of Submission:- 23-


9-1-24 1-24

Grade :

B.1 Document created by the student:

B.3 Observations and learnings

This Python program uses a while loop to find the sum of natural
numbers up to a user-input limit. It provides a hands-on
understanding of loop structures, variable manipulation, and user
interaction or learning programming fundamentals.
B.4 Conclusion:

The Python program illustrates a while loop to compute the sum


of natural numbers, engaging users in fundamental programming
concepts, including loop structures and variable manipulation,
fostering a hands-on learning experience.

B.5 Question of Curiosity

1. Write a Python program to print alphabet pattern 'E'.

Expected Output:
2. Write a Python program to check whether an alphabet is a vowel or
consonant.

Expected Output:

3. Write a Python program to sum of two given integers. However, if


the sum is between 15 to 20 it will return 20.

Expected Output

You might also like