0% found this document useful (0 votes)
12 views14 pages

Revised Manual For PPL - NEP

This is the manual for. Ppl

Uploaded by

Taqee Mushrif
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)
12 views14 pages

Revised Manual For PPL - NEP

This is the manual for. Ppl

Uploaded by

Taqee Mushrif
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/ 14

ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA

Department of Mechanical Engineering


Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Experiment 1: Introduction to Python Date:

1. Print: "Hello, World!"


 Purpose: The purpose of this program is to introduce students to the basic syntax and
structure of a Python program. It demonstrates how to use the print function to output
text to the console. This simple program serves as a foundational exercise to ensure that
students have their Python development environment set up correctly and understand
how to run a Python script.
 Objective: Introduce basic Python syntax and printing.
 Instructions: Write a Python program that prints "Hello, World!" to the console.

 Theory: The "Hello, World!" program is a simple script that outputs the text "Hello,
World!" to the screen. It is often used as the first program written by someone learning a
new programming language because it demonstrates the basic syntax and structure of
the language.
 Explanation print: This is a built-in Python function used to display the specified
message to the screen. "Hello, World!": The message to be displayed. In Python, text is
enclosed in either single (') or double (") quotation marks.
2. Basic Arithmetic Operations
 Purpose: The purpose of this program is to familiarize students with performing basic
arithmetic operations in Python. The program demonstrates how to use Python to
perform addition, subtraction, multiplication, and division. It helps students understand
how to work with variables, operators, and basic input/output functions in Python. This
exercise is fundamental for developing more complex mathematical and logical
operations in future programming tasks.
 Objective: Perform basic arithmetic operations using Python.
 Instructions: Write a Python program to perform addition, subtraction, multiplication,
and division.

1
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

 Theory: Arithmetic operations are fundamental to all programming languages and


include addition, subtraction, multiplication, and division. In Python, these operations
are performed using the following symbols:
• Addition: +
• Subtraction: -
• Multiplication: *
• Division: /
 Explanation
• 5 + 3: Adds 5 and 3, resulting in 8.
• 5 - 3: Subtracts 3 from 5, resulting in 2.
• 5 * 3: Multiplies 5 by 3, resulting in 15.
• 5 / 3: Divides 5 by 3, resulting in approximately 1.6667.
Each result is stored in a variable (result_add, result_subtract, result_multiply,
result_divide) and then printed to the screen.

3. Temperature Conversion
 Purpose: The purpose of this program is to teach students how to implement a basic
temperature conversion calculator in Python. The program typically converts temperatures
between Celsius and Fahrenheit. This exercise helps students practice using mathematical
formulas, writing functions, and handling user input and output. It also reinforces the concept
of writing reusable code and modular programming.

2
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

 Objective: Convert temperature from Celsius to Fahrenheit.


 Instructions: Write a Python program to convert temperature from Celsius to Fahrenheit
using the formula: F = (C * 9/5) + 32.
 Theory: Temperature conversion between Celsius and Fahrenheit is a common task. The
formulas for conversion are:
• From Celsius to Fahrenheit: F=95C+32F = \frac{9}{5}C + 32F=59C+32
• From Fahrenheit to Celsius: C=59(F−32)C = \frac{5}{9}(F - 32)C=95(F−32)
 Explanations:
• Assigns the value 25 to the variable celsius.
• fahrenheit = (9/5) * celsius + 32: Converts the Celsius value to Fahrenheit using the formula
and stores it in the fahrenheit variable.
• print(f"{celsius}°C is {fahrenheit}°F"): Prints the result of the conversion.

Similarly, for converting Fahrenheit to Celsius:

• fahrenheit = 77: Assigns the value 77 to the variable fahrenheit.


• celsius = (5/9) * (fahrenheit - 32): Converts the Fahrenheit value to Celsius using the formula
and stores it in the celsius variable.
• print(f"{fahrenheit}°F is {celsius}°C"): Prints the result of the conversion

3
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Viva Questions:
 Print "Hello, World!"
 What is the significance of the print function in Python?
 Why is "Hello, World!" often used as a first program in learning a new programming
language?
 How do you write comments in Python?
 What are some other basic functions available in Python similar to print?
 Can you modify the print statement to print on the same line without a newline character?
 2. Basic Arithmetic Operations
 What are the basic arithmetic operations in Python?
 How does integer division differ from regular division in Python?
 What will be the result of 5 % 2 and what does the % operator do?
 What will be the output of 2 ** 3 in Python and why?
 Explain operator precedence and how it affects arithmetic operations in Python.
Case Study:
 Write a Python program that determines whether a given number (accepted from the user)
is even or odd, and prints an appropriate message to the user.
 Write a Python program that calculates the area of a circle based on the radius entered by
the user.
 Write a Python program that accepts an integer (n) and computes the value of n+nn+nnn.
 Write a Python function to convert Fahrenheit to Celsius.
 Write a Python program to calculate the difference between a given number and 17. If the
number is greater than 17, return twice the absolute difference.

4
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Experiment 2: Data Types and Variables Date:


1. Variable Operations
 Purpose: The purpose of a Variable Operations program in Python is to demonstrate basic
arithmetic operations and how variables are used to store and manipulate data. This program
typically includes operations such as addition, subtraction, multiplication, division, and
modulus. It helps students understand the fundamental concepts of variables and how to
perform calculations using them.
 Objective: Perform operations on variables of different data types.
 Instructions: Create variables of integer, float, and string types, and perform operations on
them.

 Theory: Variable operations involve the use of variables to perform calculations and store
values. Variables can store different types of data such as integers, floats, strings, and more.
Common operations include arithmetic operations (addition, subtraction, multiplication,
division), assignment operations, and comparison operations.

2. Variable Swapping
 Purpose: The purpose of a Variable Swapping program in Python is to illustrate how to
exchange the values of two variables. This can be done using a temporary variable or more
efficiently using Python's tuple unpacking. This program helps students understand the concept
of variable assignment and the importance of efficiently managing variable values in different
scenarios.
 Objective: Swap the values of two variables without using a temporary variable.
 Instructions: Write a Python program to swap the values of two variables.
 Theory: Variable swapping is the process of exchanging the values of two variables. This can
be done in multiple ways, but Python provides a simple and intuitive way using tuple
unpacking. Swapping is useful in various algorithms, such as sorting algorithms.

5
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Viva Questions:
 Variable Operations
 What are variables in Python?
 How do you declare a variable in Python?
 What are the different types of variables in Python?
 Explain the concept of dynamic typing in Python.
 How do you perform arithmetic operations on variables?
 What is type casting and how do you do it in Python?
Case Study:-

 Write a Python program to display the first and last colors from the following list.
color_list = ["Red","Green","White" ,"Black"]
 Write a Python program to test whether a passed letter is a vowel or not.
 Write a Python program that concatenates all elements in a list into a string and returns it.
 Write a program swap two variables in Python?

6
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Experiment 3: Data Structure-String Date:

1. String Manipulation
a. Purpose: The purpose of a String Manipulation program in Python is to showcase the various
ways to work with strings. This includes concatenation, slicing, indexing, and using built-in
string methods (such as .upper(), .lower(), .replace(), etc.). This program aims to teach students
how to manipulate and handle text data effectively, which is a crucial skill in many
programming tasks.
b. Objective: Practice string manipulation techniques.
c. Instructions: Use string concatenation and slicing to modify and display strings.

Theory: String manipulation involves various operations that can be performed on strings.
These operations include concatenation, slicing, indexing, and using built-in functions like
upper(), lower(), replace(), and split(). Strings are sequences of characters and can be indexed
and sliced similarly to lists.

Viva Questions:
 String Manipulation
 What is a string in Python?
 How do you create a string in Python?
 What are some common string operations?
 How do you concatenate strings in Python?
 Explain string slicing with an example.
 What is the use of the split() and join() methods in strings?

7
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Case Study:-
 Write a program to find index value of the substring in the given string.
 Write a python program to check whether the string is Symmetrical or Palindrome
 Write a Python program to print even length words in a input string.
 Write a Python program that accepts the user's first and last name and prints them in
reverse order

8
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Experiment 4: Data Structure-List, Tuple and Dict Date:


1. List Manipulation
a. Purpose: The purpose of a List Manipulation program in Python is to showcase the various
ways to work with lists. This includes adding, removing, and modifying elements, as well as
using built-in list methods (such as append(), remove(), sort(), etc.). This program aims to teach
students how to effectively handle and manipulate list data, which is essential for many
programming tasks.
b. Objective: Practice list manipulation techniques.
c. Instructions: Use list indexing, slicing, and methods to modify and display lists.
Theory: List manipulation involves various operations that can be performed on lists. These
operations include adding, removing, and modifying elements, as well as using built-in functions
like append(), remove(), sort(), and pop(). Lists are mutable sequences, meaning their elements
can be changed, and they allow duplicate elements.
2. Tuple Manipulation
a. Purpose: The purpose of a Tuple Manipulation program in Python is to demonstrate how to
work with tuples. This includes accessing elements, concatenating tuples, and using built-in tuple
methods. Since tuples are immutable, this program emphasizes understanding the differences
between tuples and lists.
b. Objective: Practice tuple manipulation techniques.
c. Instructions: Use tuple indexing and methods to access and display tuple elements.
Theory: Tuple manipulation involves operations such as accessing elements and concatenating
tuples. Tuples are immutable sequences, meaning their elements cannot be changed after
creation. They are often used for fixed collections of items. Built-in methods for tuples include
count() and index().
3. Dictionary Manipulation
a. Purpose: The purpose of a Dictionary Manipulation program in Python is to showcase how to
work with dictionaries. This includes adding, removing, and modifying key-value pairs, as well
as using built-in dictionary methods (such as get(), keys(), values(), etc.). The program aims to
teach students how to effectively manage data using dictionaries.
b. Objective: Practice dictionary manipulation techniques.
c. Instructions: Use dictionary keys, values, and methods to modify and display dictionaries.

9
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Theory: Dictionary manipulation involves various operations that can be performed on


dictionaries. These operations include adding, removing, and modifying key-value pairs, as well
as using built-in methods like get(), keys(), values(), and items(). Dictionaries are unordered
collections of items, where each item is stored as a key-value pair, and they allow for fast
lookups.
Viva Questions
 List:
 What is a list in Python?
 How do you create a list in Python?
 Can lists hold different data types?
 What is the difference between append() and extend() methods in a list?
 Tuple:
 What is a tuple in Python?
 How is a tuple different from a list?
 Dictionary:
 What is a dictionary in Python?
 How do you create a dictionary?
 What are the key features of dictionaries?
 How can you access the value associated with a key in a dictionary?
Case Study
 Remove all occurrences of a specific element from a list.
 Write a program to find the largest and smallest elements in a list.
 Write a program to access the second element in a tuple.
 Write a program to retrieve a value using a key in a dictionary.
 Write a program to iterate over all key-value pairs in a dictionary.

10
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Experiment 5: Controls:-if-else, for and While loop Date:


1. If-Else
a. Purpose: The purpose of learning If-Else statements in Python is to understand the flow control in
a program. It helps to make decisions and execute a block of code based on certain conditions.
b. Objective: Practice using if-else statements to control the flow of a program based on different
conditions.
c. Instructions: Use if-else statements to write code that performs different actions based on various
conditions.
Theory:
If-Else statements are used for decision making in Python. The basic structure is: if condition: do
something else: do something else. The 'if' block is executed if the condition is true, otherwise, the
'else' block is executed.
2. For Loop
a. Purpose: The purpose of learning For Loop in Python is to efficiently iterate over a sequence
(such as a list, tuple, string) and perform operations on each element.
b. Objective: Practice using for loops to iterate over sequences and perform repetitive tasks.
c. Instructions: Use for loops to iterate through elements in a sequence and perform specific actions
on each element.
Theory:
For Loop in Python is used to iterate over a sequence (such as a list, tuple, string). The basic structure
is: for variable in sequence: do something. The loop continues until all elements in the sequence are
processed.
3. While Loop
a. Purpose: The purpose of learning While Loop in Python is to understand how to perform
repetitive tasks until a certain condition is met.
b. Objective: Practice using while loops to execute code repeatedly based on a condition.
c. Instructions: Use while loops to execute a block of code repeatedly as long as a specified
condition is true.
Theory:
While Loop in Python executes a block of code repeatedly as long as the specified condition is true.
The basic structure is: while condition: do something. The loop stops once the condition becomes
false.
11
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Viva Questions
 If-Else Statements
 What is an if-else statement, and when would you use it?
 Explain the syntax of an if-else statement in Python.
 Can you nest if-else statements? Provide an example.
 For Loop
 What is a for loop, and how does it work in Python?
 Explain how a for loop can be used to iterate over a list or a string.
 How would you use a for loop with the range() function? Provide an example.
 While Loop
 What is a while loop, and when would you use it?
 How does a while loop differ from a for loop?
 Explain how a while loop can potentially create an infinite loop.

Case Study:
 Write a Python program that takes an age as input and prints whether the person is a child,
teenager, adult, or senior citizen based on the age.
 Write a Python program that prints the first 10 natural numbers using a for loop.
 Write a Python program that iterates through a list of numbers and prints each number
squared.
 Write a Python program that prints numbers from 1 to 5 using a while loop.
 Write a Python program that asks the user to guess a number until they get it right, using a
while loop.

12
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Experiment 6: Functions and Modules Date:

1. Functions and Modules


a. Purpose: The purpose of a Functions and Modules program in Python is to demonstrate how
to organize and reuse code effectively. Functions allow you to encapsulate code into reusable
blocks, while modules enable you to organize functions and other code into separate files for
better structure. This program aims to teach students the importance of writing modular and
reusable code.
b. Objective: Practice defining and using functions, and organizing code into modules.
c. Instructions:
1. Write a function to perform a specific task (e.g., calculate the factorial of a number).
2. Organize multiple functions into a module and import them into another script to use.
3. Use built-in modules such as math or random to enhance your programs.
Theory:
Functions in Python are blocks of reusable code that perform a specific task. They can accept
input through parameters and return output. Functions help in breaking down complex problems
into smaller, manageable tasks. Modules in Python are files containing Python code, which can
define functions, classes, and variables. Modules help in organizing code and improving code
reusability. You can import a module using the import statement, and access its functions or
classes as needed.
Viva Questions
 What is a function in Python?
 How do you define a function in Python?
 What are arguments and parameters in the context of functions?
 What are default arguments in Python functions?
 What is the significance of *args and **kwargs in Python functions?
Case Study
 Write a function that takes a list of numbers as input and returns the sum of the numbers.
 Write a function that checks if a given string is a palindrome.
 Create a module named string_utils that has a function to count the number of words in a
string, and then write a script to use this module.

13
ANNASAHEB DANGE COLLEGE OF ENGINEERING AND TECHNOLOGY, ASHTA
Department of Mechanical Engineering
Course Name and Code: Python Programming Laboratory, 2MEVS254 Class: SY

Experiment 7: Exception Handling Date:

1. Purpose:
The purpose of Exception Handling in Python is to provide a way to manage errors gracefully.
This allows a program to continue running or to handle the error in a specific manner instead of
crashing. Exception handling helps in writing robust and error-resistant code by catching and
handling exceptions that may occur during runtime.
2. Objective:
Practice handling exceptions and errors in Python.
3. Instructions:
Use try-except blocks to catch and handle exceptions. Implement specific exceptions and finally
clauses where needed.
Theory:
Exception handling in Python is done using try, except, else, and finally blocks. The try block
contains the code that may throw an exception. The except block catches and handles the
exception if it occurs. The else block is optional and runs if no exception was raised. Finally, the
finally block is executed regardless of whether an exception occurred or not, typically used for
cleanup actions.
Viva Questions:
 What is an Exception in Python?
 How do you handle exceptions in Python?
 What is the purpose of the finally block in Python?
 Can you handle multiple exceptions in a single try-except block?
 What is the difference between except and else in exception handling?

Case Study
 Write a program that prompts the user for two numbers and handles ValueError (if the
input is not a number) and ZeroDivisionError (if the user tries to divide by zero).
 Write a function that checks if a number is positive, and raises a ValueError if it’s not.
 Create a custom exception class NegativeNumberError and raise it if a user inputs a
negative number.

14

You might also like