Lab Manual 1ala
Lab Manual 1ala
LAB MANUAL
OF
PROGRAMMING IN PYTHON LAB
(BTXCCE2203)
USING
Python IDLE or VS Code
1
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25
TABLE OF CONTENTS
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:
Never:
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
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.
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.
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
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
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
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
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
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:
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
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:
17
Lab Manual – BTXCCE 2203 – PROGRAMMING IN PYTHON LAB Poornima University, Academic Year 2024-25
Output:
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:
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
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
# c) Update list:
# - Add item to the list
my_list.append(6)
print("List after adding an item:", my_list)
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:
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