JHDHUSD
JHDHUSD
LAB MANUAL
COLLEGE
OF
ENGINEERING AND ARCHITECTURE
Prepared by:
Manuel C. Sapinit III
LAB ACTIVITIES
1. Hello World Program
2. Basic Calculator
3. Find the Largest of Three Numbers
4. Palindrome Checker
5. Fibonacci Series Generator
6. Prime Number Checker
7. Factorial Calculator
8. Temperature Conversion (Celsius to Fahrenheit)
9. Multiplication Table Generator
10. Count Vowels and Consonants in a String
11. Sum of Digits in a Number
12. List Reversal
13. Grade Classification
14. Multiplication of Matrices
15. Sorting a List
16. Dictionary Operations
17. Find the Common Elements in Two Lists
18. Text File Reader/Writer
19. Student Information System
20. Tic-Tac-Toe
Lab Activity 1
Hello World Program
Objective:
Write a Python program that outputs "Hello, World!" to the screen. This will help you set up
your environment and learn basic syntax.
Output:
Questions:
1. What is the purpose of the print () function?
Questions:
1. How would you modify the program to handle invalid inputs for numbers?
2. How can you add functionality to handle exponentiation (e.g., num1 ^ num2)?
Lab Activity 3
Find the Largest of Three Numbers
Objective:
Write a program that takes three numbers as input and outputs the largest of the three using if-
else statements.
Questions:
1. How can you simplify the code by using the max () function?
Questions:
1. What does the [::-1] slice do?
Questions:
1. What happens if you set n = 0?
2. Can you implement this using recursion instead of a loop? Rewrite the code using
recursion.
Lab Activity 6
Prime Number Checker
Objective:
Write a program that takes a number as input and checks whether it's prime or not.
Questions:
1. What is the purpose of the else block after the for loop?
2. How can you optimize the prime number check to only check up to the square root of
num?
Lab Activity 7
Factorial Calculator
Objective:
Create a program that calculates the factorial of a given number using iterative method.
Questions:
1. What is the base case in the recursive solution?
Questions:
1. How would you extend the program to handle Kelvin conversions?
Questions:
1. How would you modify the program to allow the user to specify the range (e.g., 1 to
20)?
Questions:
1. How would you handle punctuation and spaces?
Questions:
1. How does the modulus operator (%) help in extracting individual digits?
Output:
Questions:
1. What is the difference between reversing a list using slicing and using the reverse()
method?
2. Can you implement the reversal manually using a loop using a list made-up of user
input?
Lab Activity 13
Grade Classification
Objective:
Create a Python program that accepts a student's marks as input and outputs the grade (A, B, C,
etc.) based on a predefined set of criteria.
Output:
Questions:
1. How would you modify the program to classify grades into more categories (e.g., A+, B-)?
Output:
Questions:
1. How can you generalize this to multiply matrices of any size?
Output:
Questions:
1. How would you sort the list in descending order?
2. Can you implement list comprehension to expand the variety of sorting the list?
Lab Activity 16
Dictionary Operations
Objective:
Create a program that performs basic dictionary operations such as adding, updating, deleting,
and displaying key-value pairs.
Output:
Questions:
1. How can you iterate through the dictionary and print each key-value pair?
Output:
Questions:
1. What is the role of the set () function here?
Output:
Questions:
1. What happens if the file does not exist when trying to read it?
2. How would you append to the file rather than overwrite it?
Lab Activity 19
Student Information System
Objective:
Write a program that stores student information (name, roll number, marks) in a list of
dictionaries and allows operations like viewing, adding, and updating student data.
Output:
Questions:
1. How can you search for a student by their roll number?
3. Make the data output more presentable and allow users to input and save data.
Lab Activity 20
Tic-Tac-Toe Game
Objective:
Write a simple two-player Tic-Tac-Toe game using Python where players take turns to mark X
and O on the board.
Output:
Questions:
1. How would you add logic to check if a player has won?