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

Experiment - 5

This document outlines Experiment No. 5, which aims to teach the basic concepts of Python through three programming tasks: generating a Fibonacci series, summing two integers with a specific condition, and counting digits and letters in a string. It includes prerequisites, hardware and software requirements, and a theoretical overview of loops in Python, emphasizing their advantages. Additionally, it provides sample questions and answers related to Python loops and their syntax.

Uploaded by

sujeetsoni018780
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)
2 views5 pages

Experiment - 5

This document outlines Experiment No. 5, which aims to teach the basic concepts of Python through three programming tasks: generating a Fibonacci series, summing two integers with a specific condition, and counting digits and letters in a string. It includes prerequisites, hardware and software requirements, and a theoretical overview of loops in Python, emphasizing their advantages. Additionally, it provides sample questions and answers related to Python loops and their syntax.

Uploaded by

sujeetsoni018780
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/ 5

EXPERIMENT NO.

Aim / Title: To understand the Basic concept of Python

Problem Statement:
1) Write a Python program to get the Fibonacci series between 0 to 50 2) Write a Python program to sum
of two given integers. However, if the sum is between 15 to 20 it will return 20.
3) Write a Python program that accepts a string and calculates the number of digits and letters.

Objectives: Creating basic python Sketch

Outcomes: Students will be able to learn to create basic python sketch Prerequisite:

Basic knowledge of Python

Hardware requirements:
Processors: Intel Atom® processor or Intel® Core™ i3 processor.
Disk space: 1 GB
Software requirements:
Operating systems: Windows* 7 or later, macOS, and Linux.
Python versions: 2.7.X, 3.6.X. , Jupyter Notebook

Theory:
Python Loops

The flow of the programs written in any programming language is sequential by default. Sometimes we may
need to alter the flow of the program. The execution of a specific code may need to be repeated several
numbers of times.

For this purpose, programming languages provide various types of loops which are capable of repeating some
specific code several numbers of times. Consider the following diagram to understand the working of a loop
statement.

Why do we use loops in python?

The looping simplifies the complex problems into the easy ones. It enables us to alter the flow of the program so
that instead of writing the same code again and again, we can repeat the same code for a finite number of times.
For example, if we need to print the first 10 natural numbers then, instead of using the print statement 10 times,
we can print inside a loop which runs up to 10 iterations.

Advantages of loops
There are the following advantages of loops in Python.

1. It provides code reusability.


2. Using loops, we do not need to write the same code again and again. 3. Using loops, we can traverse
over the elements of data structures (array or linked lists).

There are the following loop statements in Python.

Instructions: N.A.

Program: //Paste Code here

1) Write a Python program to get the Fibonacci series between 0 to 50

2) Write a Python program to sum of two given integers. However, if the sum is between 15 to 20 it
will return 20.
3) Write a Python program that accepts a string and calculates the number of digits and letters.

Output: //Paste output’s screenshot here

Output of Fibonacci Series :

Output of Sum of two numbers :


Output of accepting a string and calculating the number of digits and letters :

Sample Viva Questions and Answers:

1. What is the syntax of for loop in python?

Ans : Python For loop is used for sequential traversal i.e. it is used for iterating
over an iterable like String, Tuple, List, Set or Dictionary.

Syntax:

for var in iterable:


# statements

2. What is the syntax of while loop in python?

Ans : Python While Loop is used to execute a block of statements repeatedly until a
the given condition is satisfied. And when the condition becomes false, the line
immediately after the loop in the program is executed.

Syntax:

while expression:
statement(s)

3. What is the syntax of do while loop in python?

Ans : Python doesn't have a do-while loop. But we can create a program like this. The
do while loop is used to check condition after executing the statement. It is
like a while loop but it is executed at least once.
General Do While Loop Syntax :

do
{
//statement
} while (condition);

4. Which one is the post tested loop?

Ans : The control structure is known as a post-test loop. This means that the code
must always be executed first and then the expression or test condition is
evaluated. If it is true, the code executes the body of the loop again.

Roll Name of Date of Date of Grade Sign of Sign of


No. Student Performance Evaluation Student Faculty

0818CS Sujeet 27/09/2022 11/10/2022


201175 Kumar Soni

You might also like