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

Experiment - 4

The document outlines Experiment No. 4, which aims to teach basic Python concepts through programming tasks such as reversing a word and counting even and odd numbers. It includes prerequisites, hardware and software requirements, and theoretical explanations of decision-making in Python, including if, if-else, and elif statements. Additionally, it provides sample questions and answers related to Python programming and its features.

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)
8 views5 pages

Experiment - 4

The document outlines Experiment No. 4, which aims to teach basic Python concepts through programming tasks such as reversing a word and counting even and odd numbers. It includes prerequisites, hardware and software requirements, and theoretical explanations of decision-making in Python, including if, if-else, and elif statements. Additionally, it provides sample questions and answers related to Python programming and its features.

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 that accepts a word from the user and reverse it.
2) Write a Python program to count the number of even and odd numbers from a series of numbers.

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:

Decision making is the most important aspect of almost all programming languages. As the name implies,
decision making allows us to run a particular block of code for a particular decision. Here, the decisions are
made on the validity of the particular conditions. Condition checking is the backbone of decision making. In
python, decision making is performed by the following statements.

Indentation in Python
For the ease of programming and to achieve simplicity, python doesn't allow the use of parentheses for the
block level code. In Python, indentation is used to declare a block. If two statements are at the same
indentation level, then they are the part of the same block.

Generally, four spaces are given to indent the statements which are a typical amount of indentation in
python. Indentation is the most used part of the python language since it declares the block of code. All
the statements of one block are intended at the same level indentation. We will see how the actual
indentation takes place in decision making and other stuff in python.
The if statement

The if statement is used to test a particular condition and if the condition is true, it executes a block of code
known as if-block. The condition of if statement can be any valid logical expression which can be either
evaluated to true or false.

The syntax of the if-statement is given below.

1. if expression:
2. statement

The if-else statement:

The if-else statement provides an else block combined with the if statement which is executed in the false case
of the condition. If the condition is true, then the if-block is executed. Otherwise, the else-block is executed.

The syntax of the if-else statement is given below.

1. if condition:
2. #block of statements
3. else:
4. #another block of statements (else-block)

The elif statement

The elif statement enables us to check multiple conditions and execute the specific block of statements
depending upon the true condition among them. We can have any number of elif statements in our program
depending upon our need. However, using elif is optional.
The elif statement works like an if-else-if ladder statement in C. It must be succeeded by an if statement.

The syntax of the elif statement is given below.

1. if expression 1:
2. # block of statements
3.
4. elif expression 2:
5. # block of statements

6.
7. elif expression 3:
8. # block of statements
9.
10. else:
11. # block of statements

Instructions: N.A.

Program: //Paste Code here


1) Write a Python program that accepts a word from the user and reverse it.

2) Write a Python program to count the number of even and odd numbers from a series of
numbers.

Output: //Paste output’s screenshot here

Output of accepts a word from the user and its reversal :

Output of count the number of even and odd numbers from a series of numbers :
Sample Viva Questions and Answers:

1. What is a dynamically typed language ?

Ans : Python is a dynamically typed language. We don't have to declare the type of
a variable or manage the memory while assigning a value to a variable in Python.
Other languages like C, C++, Java, etc.., there is a strict declaration of
variables before assigning values to them.
Python doesn't have any problem even if we don't declare the type of variable.
It states the kind of variable in the runtime of the program. So, Python is a
dynamically typed language.

2. What is pass in python ?

Ans : The pass statement is a null operation; nothing happens when it executes. The pass
is also useful in places where your code will eventually go, but has not been written.

for letter in 'Python':


if letter == 'h':
pass
print 'This is pass block'
print 'Current Letter :', letter

print "Good bye!"

3. How is Python interpreted?

Ans : Python program runs directly from the source code. - Each time Python programs are
executed code is required. - Python converts source code written by the programmer
into intermediate language which is again translated into the native language / machine
language that is executed.

4. Is Python case-sensitive?

Ans : The Python language is case-sensitive. Identifiers, keywords, and names of classes must
be written in lowercase letters. However, Python allows developers to write in uppercase
letters for constants (i.e. variables that have a value assigned to them during program
execution), and for built-in functions, and for class and module names, etc.

5. Explain the ternary operator in Python .


Ans : Ternary operators are also known as conditional expressions are operators that evaluate
something based on a condition being true or false. It was added to Python in version
2.5. It simply allows testing a condition in a single line replacing the multiline if-else
making the code compact.

Syntax :
[on_true] if [expression] else [on_false]

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


No. Student Performance Evaluation Student Faculty

0818CS Sujeet 06/09/2022 27/09/2022


201175 Kumar Soni

You might also like