2024-25
Acropolis Institute of
Technology and
Research, Indore Department of
CSE
Submitted To: Prof. Sumit Jain
(Artificial Intelligence &
Machine Learning)
Computer Workshop/Introduction to
Python-I (AL-306)
Submitted By: Vivek Devda
Enrollment No: 0827Al231149
Class/Year/Sem: AL_S-1/2rd / 3th
ACROPOLIS INSTITUTE OF TECHNOLOGY & RESEARCH,
INDORE
[LAB ASSIGNMENT Computer Workshop/Introduction to Python-I (AL-306). The objective of this laboratory work is to give
students the exposure to Object Oriented Concepts using Python and implementations. ]
Department of CSE (Artificial Intelligence & Machine Learning)
CERTIFICATE
This is to certify that the experimental work entered in this journal as per
the B. TECH. II-year syllabus prescribed by the RGPV was done by
Mr.Aditya Jadhav Student_Name B. TECH II-year, III-semester in the
Computer Workshop/Introduction to Python-I Laboratory of this
institute during the academic year 2024- 2025.
Signature of the Faculty
ABOUT THE LABORATORY
In this lab, students will be able to learn and practice Computer
Workshop/Introduction to Python-I (AL-306) concepts. Students can
expand their skill set by getting hands-on experience on various Object
Oriented concepts. The concepts & hands-on experience discussed in this
lab focuses on various data structures and inbuilt classes, libraries of
Python.
The outcome of this lab is to make students understand the structure,
utility and technologies for Python programming language.
GENERAL INSTRUCTIONS FOR LABORATORY CLASSES
⮚ DO’S
✔ Without Prior permission do not enter into the Laboratory.
✔ While entering into the LAB students should wear their ID cards.
✔ The Students should come with proper uniform.
✔ Students should sign in the LOGIN REGISTER before entering into the
laboratory.
✔ Students should come with observation and record note book to the laboratory.
✔ Students should maintain silence inside the laboratory.
✔ After completing the laboratory exercise, make sure to shutdown the
system properly.
⮚ DONT’S
✔ Students bringing the bags inside the laboratory.
✔ Students using the computers in an improper way.
✔ Students scribbling on the desk and mishandling the chairs.
✔ Students using mobile phones inside the laboratory.
✔ Students making noise inside the laboratory.
SYLLABUS
Course: AL306 Computer Workshop/Introduction to Python-I
Branch/Year/Sem: Artificial Intelligence & Machine Learning / II / III
Module1: Introduction to python language, Basic syntax, Literal Constants, Numbers,
Variable and Basic data types, String, Escape Sequences, Operators and Expressions,
Evaluation Order, Indentation, Input, Output, Functions, Comments.
Module2: Data Structure: List, Tuples, Dictionary, DataFrame and Sets, constructing,
indexing, slicing and content manipulation.
Module3: Control Flow:Conditional Statements - If, If-else, Nested If-else. Iterative
Statement - For, While, Nested Loops. Control statements - Break, Continue, Pass.
Module4: Object oriented programming:Class and Object, Attributes, Methods,
Scopes and Namespaces, Inheritance, Overloading, Overriding, Data
hiding,Exception: Exception Handling, Except clause, Try finally clause, User
Defined Exceptions.
Module5: Modules and Packages: Standard Libraries: File I/0, Sys, logging, Regular
expression, Date and Time, Network programming, multi-processing and multi
threading.
References
● Timothy A. Budd: Exploring python, McGraw-Hill Education.
● R. NageshwarRao, “Python Programming”, Wiley India
● Think Python: Allen B. Downey, O'Reilly Media, Inc.
HARDWARE AND SOFTWARE REQUIREMENTS:
S. No. Name of Item Specification
1 Computer System Hard Disk min 5 GB
RAM: 4 GB / 8 GB
Processor: Intel i3 or above
S. No. Name of Item Specification
1 Operating system Windows X/ Linux
Software and Editor Python 3.x.x
RATIONALE:
The purpose of this subject is to study the fundamental strengths and limits of cloud
services as well as how these interact with our system, computer science, and other
disciplines.
COURSE OBJECTIVES AND OUTCOMES
⮚ Course Objectives
The objective of this course is to enable students in developing understanding of the
principles of Object-Oriented Programming (OOP): classes, objects, inheritance,
polymorphism, encapsulation, and abstraction. Also, students must be able to develop
Python programs using OOP techniques to solve real-world problems.
⮚ Course Outcomes
CO1: Demonstrate a clear understanding of basic Python programming concepts, including
data types, variables, operators, loops, and control structures.
CO2: Apply these concepts to write simple Python programs for solving basic
computational problems.
CO3: Develop the ability to work with Python's built-in data structures such as lists, tuples,
sets, and dictionaries.
CO4: Utilize appropriate data structures to solve problems related to data manipulation
and storage efficiently.
CO5: Apply file handling techniques using File I/0, Sys, logging in Python programs.
Index
Grade &
Date of Date of
S.No Name of the Experiment Sign of the
Exp. Submission Faculty
1 Write Python programs using primitive data types/classes:
Integer, String with inputs and different output formatting.
2 Write a Python program for command line arguments.
3 Write various Python programs demonstrating use of If,
If-else, Nested If-else.
4 Write various Python programs demonstrating use of For,
While, Nested Loops.
5 Write Python programs using Control statements - Break,
Continue, Pass.
6 Write Python programs using List with its different methods.
7 Write Python programs using Set with its different methods.
8 Write Python programs using Tuple with its different
methods.
9 Write Python programs using Dictionary with its different
methods.
10 Write Python program to demonstrate Classes and objects
11 Write a Python program for Constructor and use the int method.
12 Write a Python program for different Inheritances and
differentiate Overloading and Overriding.
Program Outcome (PO)
The engineering graduate of this institute will demonstrate:
a) Apply knowledge of mathematics, science, computing and engineering fundamentals to computer
science engineering problems.
b) Able to identify, formulate, and demonstrate with excellent programming, and problem solving skills.
c) Design solutions for engineering problems including design of experiment and processes to meet
desired needs within reasonable constraints of manufacturability, sustainability, ecological,
intellectual and health and safety considerations.
d) Propose and develop effective investigational solution of complex problems using research
methodology; including design of experiment, analysis and interpretation of data, and combination of
information to provide suitable conclusion. synthesis
e) Ability to create, select and use the modern techniques and various tools to solve engineering problems
and to evaluate solutions with an understanding of the limitations.
f) Ability to acquire knowledge of contemporary issues to assess societal, health and safety, legal and
cultural issues.
g) Ability to evaluate the impact of engineering solutions on individual as well as organization in a
societal and environmental context, and recognize sustainable development, and will be aware of
emerging technologies and current professional issues.
h) Capability to possess leadership and managerial skills, and understand and commit to professional
ethics and responsibilities.
i) Ability to demonstrate the team work and function effectively as an individual, with an ability to
design, develop, test and debug the project, and will be able to work with a multi-disciplinary team.
j) Ability to communicate effectively on engineering problems with the community, such as being able to
write effective reports and design documentation.
k) Flexibility to feel the recognition of the need for, and have the ability to engage in independent and life-
long learning by professional development and quality enhancement programs in context of
technological change.
l) A practice of engineering and management principles and apply these to one’s own work, as a member
and leader in a team, to manage projects and entrepreneurship
Q1.Write Python programs using primitive data types/classes: Integer, String with inputs and different output
formatting.
Integer and String Input/Output Formatting
num = int(input("Enter an integer: "))
print(f"Decimal: {num}, Hex: {hex(num)}, Octal: {oct(num)}, Binary: {bin(num)}")
name = input("Enter your name: ")
print(f"Uppercase: {name.upper()}, Lowercase: {name.lower()}, Title Case: {name.title()}")
print(f"Right-aligned (20 chars): {name:>20}, Centered (20 chars): {name:^20}")
# Example Input/Output:
# Enter an integer: 42
# Decimal: 42, Hex: 0x2a, Octal: 0o52, Binary: 0b101010
# Enter your name: John Doe
# Uppercase: JOHN DOE, Lowercase: john doe, Title Case: John Doe
# Right-aligned (20 chars): John Doe, Centered (20 chars): John Doe
Q2.Write a Python program for command line arguments.
Command Line Arguments
import sys
if len(sys.argv) > 1:
print("Command line arguments:", sys.argv[1:])
else:
print("No command line arguments provided.")
# Output: Command line arguments: ['arg1', 'arg2']
# If executed as: python my_script.py
# Example Output: No command line arguments provided.
Q 3.Write various Python programs demonstrating use of If, If-else, Nested If-else.
If, If-else, Nested If-else
age = int(input("Enter your age: "))
if age < 13:
print("Child")
elif 13 <= age < 18:
print("Teenager")
else:
print("Adult")
if age > 10:
if age % 2 == 0:
print("Age is even and greater than 10")
else:
print("Age is odd and greater than 10")
# Output:
# Enter your age: 15
# Teenager
# Age is odd and greater than 10
Q 4. Write various Python programs demonstrating use of For, While, Nested Loops.
For, While, Nested Loops
print("For loop:")
for i in range(5):
print(i, end=" ")
# Output: 0 1 2 3 4
print("\nWhile loop:")
i=0
while i < 5:
print(i, end=" ") # Output: 0 1 2 3 4
i += 1
print("\nNested loops:")
for i in range(3):
for j in range(2):
print(f"({i},{j})", end=" ")
# Output: (0,0) (0,1) (1,0) (1,1) (2,0) (2,1)
print() #Newline for each outer loop
Q5.Write Python programs using Control statements - Break, Continue, Pass.
Break, Continue, Pass
print("Break, Continue, Pass:")
for i in range(10):
if i == 3:
continue # Skips 3
if i == 7:
break # Exits loop at 7
if i == 5:
pass # Does nothing
print(i, end=" ")
# Output: 0 1 2 4 6
Q 6.Write Python programs using List with its different methods.
List Methods
my_list = [1, 2, 3]
my_list.append(4) # Adds 4 to the end: [1, 2, 3, 4]
my_list.insert(1, 10) # Inserts 10 at index 1: [1, 10, 2, 3, 4]
my_list.extend([5, 6]) # Extends list: [1, 10, 2, 3, 4, 5, 6]
removed_item = my_list.pop(2) #Removes and returns item at index 2 (2): [1, 10, 3, 4, 5, 6]
print(f"List: {my_list}, Removed item: {removed_item}")
# Output: List: [1, 10, 3, 4, 5, 6], Removed item: 2
my_list.remove(5) # Removes first occurrence of 5: [1, 10, 3, 4, 6]
print(f"List after removing 5: {my_list}")
# Output: List after removing 5: [1, 10, 3, 4, 6]
print(f"Index of 6: {my_list.index(6)}")
# Output: Index of 6: 4
my_list.sort()
print(f"Sorted list: {my_list}")
# Output: Sorted list: [1, 3, 4, 6, 10]
my_list.reverse()
print(f"Reversed list: {my_list}")
# Output: Reversed list: [10, 6, 4, 3, 1]
Q7.Write Python programs using Set with its different methods.
Set Methods
my_set = {1, 2, 3}
my_set.add(4) # Adds 4: {1, 2, 3, 4}
my_set.remove(2) # Removes 2: {1, 3, 4}
set2 = {3, 4, 5}
print(f"Set: {my_set}, Union: {my_set.union(set2)}, Intersection: {my_set.intersection(set2)}, Difference:
{my_set.difference(set2)}")
# Output: Set: {1, 3, 4}, Union: {1, 3, 4, 5}, Intersection: {3, 4}, Difference: {1}
Q8.Write Python programs using Tuple with its different methods.
Tuple Methods
my_tuple = (1, 2, 2, 3)
print(f"Tuple: {my_tuple}, Count of 2: {my_tuple.count(2)}, Index of 3: {my_tuple.index(3)}")
# Output: Tuple: (1, 2, 2, 3), Count of 2: 2, Index of 3: 3
9.Write Python programs using Dictionary with its different methods.
Dictionary Methods
my_dict = {"a": 1, "b": 2}
my_dict["c"] = 3 # Adds key-value pair: {'a': 1, 'b': 2, 'c': 3}
print(f"Dictionary: {my_dict}, Keys: {my_dict.keys()}, Values: {my_dict.values()}, Items: {my_dict.items()},
Value of 'a': {my_dict.get('a')}")
# Output: Dictionary: {'a': 1, 'b': 2, 'c': 3}, Keys: dict_keys(['a', 'b', 'c']), Values: dict_values([1, 2, 3]), Items:
dict_items([('a', 1), ('b', 2), ('c', 3)]), Value of 'a': 1
print(my_dict.get('d')) #Returns None if key is not present
# Output: None
Q10.Write Python program to demonstrate Classes and objects
Classes and Objects
class Dog:
def init (self, name, breed):
self.name = name
self.breed = breed
def bark(self):
print("Woof!")
my_dog = Dog("Buddy", "Golden Retriever")
print(f"Dog's name: {my_dog.name}") # Output: Dog's name: Buddy
my_dog.bark()
# Output: Woof!
Q11. Write a Python program for Constructor and use the init method.
Constructor ( init )
class Car:
def init (self, make, model):
self.make = make
self.model = model
def display(self):
print(f"Car: {self.make} {self.model}")
my_car = Car("Toyota", "Camry")
my_car.display()
#Output: Car: Toyota Camry
Q12.Write Python program for different Inheritances and differentiate Overloading and Overriding.
class Animal: # Base class
def init (self, name):
self.name = name
def make_sound(self):
print("Generic animal sound")
class Mammal(Animal): # Inherits from Animal
def init (self, name, fur_color):
super(). init (name) # Call parent's constructor
self.fur_color = fur_color
def give_birth(self):
print(f"{self.name} gives birth to live young.")
class Dog(Mammal): # Inherits from Mammal (Multi-level Inheritance)
def init (self, name, fur_color, breed):
super(). init (name, fur_color)
self.breed = breed
def make_sound(self, volume=None): # Overriding and Simulated Overloading
if volume:
print(f"Woof! at {volume} volume.")
else:
print("Woof!")
def wag_tail(self):
print(f"{self.name} wags its tail.")
class Cat(Mammal): #Inherits from Mammal
def init (self, name, fur_color, breed):
super(). init (name, fur_color)
self.breed = breed
def make_sound(self): # Overriding
print("Meow!")
# Demonstrate Inheritance
my_dog = Dog("Buddy", "Golden", "Golden Retriever")
my_dog.make_sound() # Output: Woof! (Overriding)
my_dog.make_sound("Loud") # Output: Woof! at Loud volume. (Simulated Overloading)
my_dog.wag_tail() # Output: Buddy wags its tail.
my_dog.give_birth() #Output: Buddy gives birth to live young. (Inherited from Mammal)
my_cat = Cat("Whiskers", "Black", "Persian")
my_cat.make_sound() # Output: Meow! (Overriding)
my_cat.give_birth() #Output: Whiskers gives birth to live young. (Inherited from Mammal)
my_animal = Animal("Generic Animal")
my_animal.make_sound() # Output: Generic animal sound
# Demonstrate is instance and is subclass
print(isinstance(my_dog, Dog)) # Output: True
print(isinstance(my_dog, Mammal)) # Output: True (Dog is a Mammal)
print(isinstance(my_dog, Animal)) # Output: True (Dog is an Animal)
print(isinstance(my_animal, Dog)) # Output: False
print(issubclass(Dog, Mammal)) # Output: True
print(issubclass(Mammal, Animal))# Output: True
print(issubclass(Dog, Animal)) # Output: True
print(issubclass(Animal, Dog)) # Output: False