0% found this document useful (0 votes)
2 views7 pages

Basic Python

This lab manual for the Object Oriented System Design course at the National Institute of Technology Sikkim outlines various programming exercises in Python. It covers topics such as procedural vs object-oriented programming, loops, conditional statements, operators, patterns, and functions, with tasks designed to enhance students' understanding of these concepts. The manual includes detailed tasks and sample code to guide students through the learning process.

Uploaded by

Suman Das
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)
2 views7 pages

Basic Python

This lab manual for the Object Oriented System Design course at the National Institute of Technology Sikkim outlines various programming exercises in Python. It covers topics such as procedural vs object-oriented programming, loops, conditional statements, operators, patterns, and functions, with tasks designed to enhance students' understanding of these concepts. The manual includes detailed tasks and sample code to guide students through the learning process.

Uploaded by

Suman Das
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/ 7

रा ीय प्रौद्यो गक सं ान स क्कम

National Institute of Technology Sikkim

Lab Manual: Object Oriented System Design


(CS13204)

Implemented in Python

Course Instructor: Dr. Pankaj Kumar Keserwani

Department of Computer Science and Engineering

August 8, 2025
Lab Manual (Python) CS13104: Object Oriented System Design

Contents

Lab 1: Procedural vs Object-Oriented Programming 2

1
Lab Manual (Python) CS13104: Object Oriented System Design

Lab 1: Procedural vs Object-Oriented Programming


Objective: To introduce students to the paradigm shift from procedural to object-
oriented programming.
Expected Outcome: Students will understand key differences and gain the ability to
convert procedural logic to class-based design.
Task Description: Write a program to calculate student grades using procedural
programming. Rewrite it using object-oriented principles with a class ‘Student‘.
Sample Code:
# Procedural Approach
def calculate_grade ( marks ):
if marks >= 90:
return "A"
elif marks >= 80:
return "B"
return "C"

print ( calculate_grade (85))

# OOP Approach
class Student :
def __init__ (self , name , marks ):
self.name = name
self. marks = marks
def grade (self):
if self. marks >= 90:
return "A"
elif self. marks >= 80:
return "B"
return "C"

s = Student (" Alice ", 85)


print (s. grade ())

Objective: To practice fundamental Python programming concepts including loops,


conditional statements, patterns, switch-case, functions, and recursion.

Part A: For / While / Do-While Loops (7 Questions)


1. Print the first 10 natural numbers using a for loop.
2. Display the multiplication table of a given number using a while loop.
3. Calculate the sum of all even numbers between 1 and 100.
4. Find the factorial of a number using a while loop.
5. Reverse the digits of a number using a loop.
6. Generate the Fibonacci series up to n terms using a loop.
7. Keep asking the user for input until they enter a negative number (simulate do-while
logic in Python).

2
Lab Manual (Python) CS13104: Object Oriented System Design

Part B: If-Else & Nested If-Else (6 Questions)


8. Check whether a given number is positive, negative, or zero.

9. Check whether a given number is even or odd.

10. Find the largest of two numbers.

11. Find the largest of three numbers using nested if-else.

12. Check whether a year is a leap year or not.

13. Accept marks from the user and print the grade based on percentage.

Part C: Operators:Arithmetic, logical, and assignment (6 Ques-


tions)
14. Write a Python program takes two integer inputs from the user, calculates their
sum, difference, product, and quotient, and then prints the results.

15. Create a program that uses the exponentiation operator (**) to calculate the square
of a number provided by the user.

16. Write a script that demonstrates the use of the floor division (//) and modulus (%)
operators by dividing two user-provided numbers and printing both the quotient
and the remainder.

17. Develop a Python program that uses augmented assignment operators (+=, -=,
*=) to modify the value of a variable. Start with an initial value of 10 and perform
a series of operations to show the change.

18. Create a program that determines if a given year is a leap year. Use comparison
and logical operators to implement the leap year conditions: a year is a leap year
if it is divisible by 4, except for years divisible by 100 but not by 400.

19. Write a program that uses the identity operators (is, is not) to compare two variables
that hold the same value but are assigned differently (e.g., a = 5, b = 5, and a
third variable c = a). Print the results of a is b and a is c. Explain the output.

20. Swap Two Numbers Using Bitwise XOR


Without using a temporary variable, swap two integers using the ̂ (XOR) operator.

21. Check if a Number is Even or Odd Using Bitwise AND


Use the & operator to determine whether a number is even or odd.

22. Count the Number of Set Bits (1s) in a Number


Use bitwise operators (& and >>) to count how many bits are set in the binary
representation of a given number.

23. Multiply a Number by 2 Using Bitwise Shift


Use the left shift operator << to multiply a number by 2 without using the *
operator.

3
Lab Manual (Python) CS13104: Object Oriented System Design

24. Toggle a Specific Bit in a Number


Write a program that takes a number and a bit position, then flips (toggles) the
bit at that position using ̂.

Part D — Patterns (visual examples)


1. Right-angled triangle of ‘*‘ (height = 5)

*
**
***
****
*****

2. Centered pyramid of ‘*‘ (height = 5)

*
***
*****
*******
*********

3. Inverted pyramid of ‘*‘ (height = 5)

*********
*******
*****
***
*

4. Numbers 1..5 in a right-angled triangle

1
12
123
1234
12345

5. Floyd’s triangle (5 rows)

1
2 3
4 5 6
7 8 9 10
11 12 13 14 15

4
Lab Manual (Python) CS13104: Object Oriented System Design

6. Diamond of ‘*‘ (odd height = 5)

*
***
*****
***
*

7. Hollow square of ‘*‘ (size = 5)

*****
* *
* *
* *
*****

Part D: Switch Case (Match-Case in Python 3.10+) (5 Ques-


tions)
25. Create a calculator that performs +, -, *, / based on user choice.

26. Print the name of the day based on day number (1=Monday, 2=Tuesday...).

27. Check whether a given vowel is ‘a‘, ‘e‘, ‘i‘, ‘o‘, or ‘u‘.

28. Display different greetings based on the time of the day (morning, afternoon,
evening).

29. Convert a number (1–12) to its corresponding month name.

Part E: Functions & Recursive Functions (5 Questions)


30. Write a function to calculate the square of a number.

31. Write a function to calculate the sum of two numbers.

32. Write a function to check whether a number is prime or not.

33. Write a recursive function to calculate factorial.

34. Write a recursive function to print the Fibonacci series.

Part F: Additional Interactive Exercises:


1. Bank Account Manager Procedural: Write functions to deposit, withdraw,
and display account balance. OOP: Create a BankAccount class with methods
deposit(), withdraw(), and display_balance().

5
Lab Manual (Python) CS13104: Object Oriented System Design

2. Student Report Generator Procedural: Store names and marks in lists, then
print grades. OOP: Create a Student class with grade() and display() methods,
and store objects in a list.

3. Temperature Converter Procedural: Functions to convert Celsius ↔ Fahrenheit.


OOP: Create a Temperature class with methods to_celsius() and to_fahrenheit().

4. Simple Calculator Procedural: Functions for add, subtract, multiply, divide.


OOP: Create a Calculator class with corresponding methods, allowing continu-
ous calculations.

5. E-commerce Cart Procedural: Store items in a list and calculate total price.
OOP: Create an Item class and a Cart class with methods to add/remove items
and calculate total price.

6. Library Management System Procedural: Use dictionaries to store book titles


and their availability. Write functions to borrow and return books. OOP: Create
a Book class and a Library class with methods to borrow, return, and display
available books.

7. Employee Payroll System Procedural: Store employee details and calculate


salary based on hours worked and hourly rate. OOP: Create an Employee class
with attributes for name, hourly rate, and hours worked, and a method to calculate
salary.

8. Quiz Game Procedural: Use lists to store questions and answers, and check user
responses. OOP: Create a Question class and a Quiz class to handle question
display, answer checking, and score tracking.

9. Inventory Tracker Procedural: Store product details in lists or dictionaries and


update stock manually. OOP: Create a Product class with attributes like name,
price, and quantity, and methods to add/remove stock.

10. Simple To-Do List Procedural: Store tasks in a list and mark them as done.
OOP: Create a Task class and a ToDoList class with methods to add, remove, and
mark tasks as complete.

11. Digital Clock Procedural: Use a function to display the current time every second
using time module. OOP: Create a Clock class that continuously updates and
displays time.

12. Movie Ticket Booking System Procedural: Store available seats in a list and
update when booked. OOP: Create a Movie class with methods to show available
seats and book tickets.

You might also like