100% found this document useful (1 vote)
41 views24 pages

Lab Manual 1ala

The lab manual for Programming in Python (BTXCCE 2203) at Poornima University outlines the rules, instructions, syllabus, and objectives for the course during the academic year 2024-25. It includes a detailed list of lab exercises, a marks scheme for evaluation, and resources for students. The manual emphasizes skill development, problem-solving, and the application of programming concepts through practical exercises.
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
100% found this document useful (1 vote)
41 views24 pages

Lab Manual 1ala

The lab manual for Programming in Python (BTXCCE 2203) at Poornima University outlines the rules, instructions, syllabus, and objectives for the course during the academic year 2024-25. It includes a detailed list of lab exercises, a marks scheme for evaluation, and resources for students. The manual emphasizes skill development, problem-solving, and the application of programming concepts through practical exercises.
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/ 24

Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

LAB MANUAL
OF
PROGRAMMING IN PYTHON LAB
(BTXCCE2203)

USING
Python IDLE or VS Code

B. Tech Regular I Year II Semester


Academic Session
2024-2025

1
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

TABLE OF CONTENTS

S.No. Contents Page No.


1 Lab Rules 2-3
2 Instructions 4
3 Syllabus 5
4 Marks Scheme 6
5 Lab Plan 7
6 Lab objective 8
7 List of lab exercises 9
8 Resources 10
9 Experiments 11-47

2
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

LAB RULES
Responsibilities of Users
Users are expected to follow some fairly obvious rules of conduct:

Always:

 Enter the lab on time and leave at proper time.


 Wait for the previous class to leave before the next class enters.
 Keep the bag outside in the respective racks.
 Utilize lab hours in the corresponding.
 Turn off the machine before leaving the lab unless a member of lab staff has specifically told you not
to do so.
 Leave the labs at least as nice as you found them.
 If you notice a problem with a piece of equipment (e.g. a computer doesn't respond) or the room in
general (e.g. cooling, heating, lighting) please report it to lab staff immediately. Do not attempt to fix
the problem yourself.

Never:

 Don't abuse the equipment.


 Do not adjust the heat or air conditioners. If you feel the temperature is not properly set, inform lab
staff; we will attempt to maintain a balance that is healthy for people and machines.
 Do not attempt to reboot a computer. Report problems to lab staff.
 Do not remove or modify any software or file without permission.
 Do not remove printers and machines from the network without being explicitly told to do so by lab
staff.
 Don't monopolize equipment. If you're going to be away from your machine for more than 10 or 15
minutes, log out before leaving. This is both for the security of your account, and to ensure that others
are able to use the lab resources while you are not.

3
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

 Don’t use internet, internet chat of any kind in your regular lab schedule.
 Do not download or upload of MP3, JPG or MPEG files.
 No games are allowed in the lab sessions.
 No hardware including USB drives can be connected or disconnected in the labs without prior
permission of the lab in-charge.
 No food or drink is allowed in the lab or near any of the equipment. Aside from the fact that it leaves a
mess and attracts pests, spilling anything on a keyboard or other piece of computer equipment could
cause permanent, irreparable, and costly damage. (and in fact has) If you need to eat or drink, take a
break and do so in the canteen.
 Don’t bring any external material in the lab, except your lab record, copy and books.
 Don’t bring the mobile phones in the lab. If necessary then keep them in silence mode.
 Please be considerate of those around you, especially in terms of noise level. While labs are a natural
place for conversations of all types, kindly keep the volume turned down.

If you are having problems or questions, please go to either the faculty, lab in-charge or the lab supporting staff.
They will help you. We need your full support and cooperation for smooth functioning of the lab.

4
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

INSTRUCTIONS

Before entering in the lab

All the students are supposed to prepare the theory regarding the next experiment.
Students are supposed to bring the practical file and the lab copy.
Previous programs should be written in the practical file.
All the students must follow the instructions, failing which he/she may not be allowed in the lab.

While working in the lab

Adhere to experimental schedule as instructed by the lab in-charge.


Get the previously executed program signed by the instructor.
Get the output of the current program checked by the instructor in the lab copy.
Each student should work on his/her assigned computer at each turn of the lab.
Take responsibility of valuable accessories.
Concentrate on the assigned practical and do not play games
If anyone caught red handed carrying any equipment of the lab, then he/she will have to face serious
consequences.

5
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

PROGRAMMING IN
Code: BTXCCE2203 2 Credit [LTP:0-0-4]
PYTHON LAB
Part A
1. a) Write a python program to check if the number is prime or not.
b) Write a python program to find greatest of four numbers entered by user.

2. Write and run a Python program that asks the user for a temperature in
Celsius and converts and output the temperature in Fahrenheit.

3. Write python program to perform following operations on Lists:


a) Create list
b) Access list
c) Update list (Add item, Remove item)
d) Delete list

4. Here is an algorithm to print out n! (n factorial) from 0! to 19!:


1. Set f = 1
2. Set n = 0
3. Repeat the following 20 times:
a. Output n, "! = ", f
b. Add 1 to n
c. Multiply f by n
Using a for loop, write and run a Python program for this algorithm.

5. Modify the program above using a while loop so it prints out all of the
factorial values that are less than 1 billion.

6. Write a python program to find the minimum in the array and find its index in
the array.
Part B
7. Write a python program to implement bubble sort using function.

8. Write a python program to read 3 subject marks and display pass or failed
using class and object.

9. Draw the Target symbol (a set of concentric Squares, alternating red and
white) in a graphics window that is 200 pixels wide by 200 pixels high. Hint:
Draw the largest circle first in red, then draw the next smaller circle in white,
then draw the next smaller circle in red. Graphical objects drawn later appear
"on top of" graphical objects drawn earlier.

6
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

10.
Create a 5 X 5 rectangle whose top left corner is at (row*5, col*5). (Where is
the bottom right corner?) If the sum of the row and col numbers is even, set
the fill color of the rectangle to white, otherwise set it to black. Then draw the
rectangle.

7
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

MARKS SCHEME

Examination Marks Scheme

A. Practical (Laboratory) Subjects:-


a. Continuous Internal Evaluation (CIE) 40%
- CIE-I (Pr.):Performance, Lab Record, Viva, Attendance and 20%
Discipline
- CIE-II(Pr.):Performance, Lab Record, Viva, Attendance and 20%
Discipline
b. Mid Semester Exam (MSE)– One 20 %
c. End Semester Exam (ESE) – One 40%
TOTAL 100 %

Internal Assessment System

Total Marks – 10

Performance
Attendance Discipline Record Total
& Viva
1 1 3 5 10

8
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

LAB PLAN

Total number of experiment 10


Total number of turns required 10
Number of turns required for

Experiment Number Turns Required Turn No.

Exp. 1 1 1

Exp. 2 1 2

Exp.3 1 3

Exp.4 1 4

Exp.5 1 5

Exp.6 1 6

Exp.7 1 7

Exp.8 1 8

Exp.9 1 9

Exp.10 1 10

Distribution of lab hours


Attendance 05 minutes
Explanation of features of language 15 minutes
Explanation of experiment 15 minutes
Performance of experiment 70 minutes
Viva / Quiz / Queries 15 minutes
Total 120 minutes

9
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Lab Objective

 Skill Development: Reinforce and enhance programming skills through practical exercises
that involve writing, debugging, and executing Python code.
 Problem-Solving: Develop problem-solving abilities by presenting real-world scenarios and
guiding students to implement Python solutions to these problems.
 Application of Concepts: Apply theoretical knowledge acquired in lectures to real-world
situations, fostering a deeper understanding of Python programming concepts such as
variables, data types, loops, and functions.
 Project Work: Encourage collaborative and individual project work to allow students to
create practical applications, reinforcing their understanding of Python and promoting
creativity in problem-solving.
 Debugging and Troubleshooting: Enhance debugging skills by introducing common errors
and issues for students to identify, analyze, and resolve within their Python code.
 Version Control: Introduce version control systems like Git to teach students how to manage
and track changes in their code, fostering good programming practices.
 Algorithm Implementation: Provide opportunities for students to implement algorithms and
data structures using Python, reinforcing algorithmic thinking and efficiency considerations.
 Library and Framework Usage: Familiarize students with popular Python libraries and
frameworks, such as NumPy, Pandas, Flask, or Django, depending on the course focus, to
expose them to real-world applications and industry practices.
 Testing and Quality Assurance: Introduce testing methodologies, such as unit testing, and
emphasize the importance of writing code that is not only functional but also reliable and
maintainable.
 Documentation: Emphasize the significance of documenting code, encouraging students to
write clear and concise comments and documentation to enhance code readability and
facilitate collaboration.

10
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

List of Lab Exercises

Sr. No. Name of experiment


Cycle-1
1. a) Write a python program to check if the number is prime or not.
b) Write a python program to find greatest of four numbers entered by user.
2. Write and run a Python program that asks the user for a temperature in Celsius and
converts and output the temperature in Fahrenheit.
3. Write python program to perform following operations on Lists:
a) Create list
b) Access list
c) Update list (Add item, Remove item)
d) Delete list
4. Here is an algorithm to print out n! (n factorial) from 0! to 19!:
1. Set f = 1
2. Set n = 0
3. Repeat the following 20 times:
a. Output n, "! = ", f
b. Add 1 to n
c. Multiply f by n
Using a for loop, write and run a Python program for this algorithm.
5. Modify the program above using a while loop so it prints out all of the factorial
values that are less than 1 billion.
6. Write a python program to find the minimum in the array and find its index in the
array.
Cycle-2
7. Write a python program to implement bubble sort using function.
8. Write a python program to read 3 subject marks and display pass or failed using
class and object.
9. Draw the Target symbol (a set of concentric Squares, alternating red and white) in
a graphics window that is 200 pixels wide by 200 pixels high. Hint: Draw the
largest circle first in red, then draw the next smaller circle in white, then draw the
next smaller circle in red. Graphical objects drawn later appear "on top of"
graphical objects drawn earlier.

11
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

10. Create a 5 X 5 rectangle whose top left corner is at (row*5, col*5). (Where is the
bottom right corner?) If the sum of the row and col numbers is even, set the fill
color of the rectangle to white, otherwise set it to black. Then draw the rectangle.

12
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Resources for all the labs


Hardware :
1. Computer &
2. Peripheral devices

Software:
1. Python IDLE
2. PyCharm
3. VS Code

Text Books:
1. Core Python Programming, Chun, JWesley, 2007, Pear son
2. Head First Python, Barry,Paul, 2010, ORielly

Reference Books:
Learning Python Lutz, Mark O Rielly, 2009

Reference Websites:
1. https://www.learnpython.org/
2. https://realpython.com/start-here/
3. https://www.programiz.com/python-programming
4. https://www.w3schools.com/python

13
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Experiments

14
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Experiment No.:1
a) Write a python program to check if the number is prime or not.

Aim: To write a Python program that checks whether a given number is prime or not.

Algorithm:
1. Start.
2. Read an integer num from the user.
3. Check if num <=1:
If true, print that num is not a prime number and stop.
4. Initialize a variable is_prime as True.
5. Iterate i from 2 to num - 1:
6. Check if num % i == 0 (i.e., num is divisible by i):
If true, set is_prime to False and break the loop.
7. Check the value of is_prime:
If is_prime is True, print that num is a prime number.
Otherwise, print that num is not a prime number.
8. Stop.

Program:

# Program to check if a number is prime or not


# Input from user
num = int(input("Enter a number to check if it's prime: "))
# Prime number check
if num <= 1:
print(f"{num} is not a prime number.")
else:
is_prime = True
for i in range(2,num):
if num % i == 0:
is_prime = False
break
if is_prime:
print(f"{num} is a prime number.")
else:
print(f"{num} is not a prime number.")

15
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Output:

Viva-Questions:
1. Why do we need to use int() while taking input for numbers?
2. How do you check if a number is divisible by another number in Python?
3. What is the significance of checking divisibility up to the square root of a
number?
4. How does the break statement affect the control flow of a loop?
5. Explain the difference between the for loop and while loop in Python.
6. How is a for loop implemented in Python? Can you iterate over a dictionary?

16
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

b) Write a python program to find greatest of four numbers entered by user.

Aim: To write a Python program that finds the greatest of four numbers entered by the user.

Algorithm:
1. Start.
2. Input four numbers from the user and store them in variables a, b, c, and d.
3. Compare the numbers using nested if statements:
If a > b and a > c and a > d, set greatest = a.
Else if b > c and b > d, set greatest = b.
Else if c > d, set greatest = c.
Else, set greatest = d.
4. Print the greatest number.
5. Stop.

Program:

# Program to find the greatest of four numbers

# Input from the user


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
d = int(input("Enter fourth number: "))

# Finding the greatest number


if a > b and a > c and a > d:
greatest = a
elif b > c and b > d:
greatest = b
elif c > d:
greatest = c
else:
greatest = d

# Display the result


print(f"The greatest number is: {greatest}")

17
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Output:

Use Case: Prime check: cryptography; Greatest number: comparisons in decision-making


tasks.

Viva Questions:
1. What are conditional statements in Python?
2. How does the max() function in Python work?
3. What data types can be used with comparison operators?
4. Explain the difference between if-elif and nested if statements.
5. What are Python’s decision-making statements?
6. What is the difference between break, continue, and pass?

18
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Experiment No.:2
Name of Experiment: Write and run a Python program that asks the user for a
temperature in Celsius and converts and output the temperature in Fahrenheit.

Aim: To write a Python program that asks the user to input a temperature in Celsius and
converts it to Fahrenheit, displaying the result.

Algorithm:

1. Start.
2. Input the temperature in Celsius from the user.
3. Apply the formula for conversion from Celsius to Fahrenheit:

4. Output the temperature in Fahrenheit.


5. Stop.

Code:
#Aim: write a Program to convert celcius to fahrenheit
# Ask the user for temperature in Celcius
celsius = float(input("Enter temperature in Celsius: "))
# Convert Celsius to Fahrenheit
fahrenheit = (celsius * 9/5) + 32
#Output the temperature in Fahrenheit
print("The temperature in Fahrenheit is:", fahrenheit)

Output:

Use Case: Program converts Celsius to Fahrenheit based on user input temperature.

Viva Questions:
1. What are the built-in data types in Python?
2. What is the purpose of using the float() function in Python for taking
temperature input?

19
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

3. How do you handle user input in Python?


4. What data type is appropriate for handling temperatures, and why?
5. How does the print() function work in Python?
6. What would happen if the program is given a non-numeric input (like a
string)? How would you handle this?

20
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Experiment No.: 3
Name of Experiment: Write python program to perform following operations on Lists:
a) Create list
b) Access list
c) Update list (Add item, Remove item)
d) Delete list

Aim: To demonstrate creating, accessing, updating, and deleting operations on lists in


Python, including adding/removing items.
Program:
# a) Create a list
my_list = [1, 2, 3, 4, 5]

# b) Access list (accessing the first item)


print("First item in the list:", my_list[0])

# c) Update list:
# - Add item to the list
my_list.append(6)
print("List after adding an item:", my_list)

# - Remove item from the list


my_list.remove(3)
print("List after removing an item:", my_list)

# d) Delete the list


del my_list
print("List deleted successfully.")

Output:

21
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Viva Questions:
1. What is a list in Python and how is it different from other data structures like tuples or
sets?
2. How do you access an element from a list using its index?
3. What are the methods to add an item to a list in Python?
4. What is the difference between remove() and pop() when deleting items from a list?
5. What will happen if you try to access an index that does not exist in the list?
6. Explain the difference between append() and insert() methods in lists.
7. What is the purpose of the del keyword in Python, and how is it used to delete a list?

22
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Experiment No.: 4
Name of Experiment:
Here is an algorithm to print out n! (n factorial) from 0! to 19!:
1. Set f = 1
2. Set n = 0
3. Repeat the following 20 times:
a. Output n, "! = ", f
b. Add 1 to n
c. Multiply f by n
Using a for loop, write and run a Python program for this algorithm.

Aim: To write a Python program that calculates and prints the factorial of numbers from 0!
to 19!, using a loop.

Program:

# Python program to print factorial of numbers from 0! to 19!


# Initialize variables
f=1
n=0
# Loop to calculate and print factorials from 0! to 19!
for n in range(20):
print(f"{n}! = {f}")
# Multiply f by the next number for the next factorial computation
f *= (n + 1)

Output:

23
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25

Viva Questions:
1. What is the factorial of a number, and why is it important in programming?
2. What changes needed in the program to print the factorial of a number entered by user?
3. Explain the use of a loop in calculating the factorial.
4. What will happen if the value of n is negative? How should the program handle this?
5. What is the purpose of multiplying f by (n+1) in the loop?
6. If you were to calculate factorials for numbers larger than 19, what issues might arise,
and how can they be addressed?
7. How would you modify the program to calculate and print factorials for numbers from 20
to 30?

24

You might also like