Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
17 views

Python Lablists

Uploaded by

syamantoksaha8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Python Lablists

Uploaded by

syamantoksaha8
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 39

NAME = Syamantok Saha

ROLL NO = 23BEC076

BRANCH = ECE

BATCH = DIV-2, F-3

SUBJECT = PYTHON LAB


LAB FILE - 1

QUESTION-1
1. Discuss their programming background. Which languages do they know? Did they
know/participating in any programming competitions such as hacker rank?
Ans: Python holds immense importance in undergraduate programs due to its versatility,
simplicity, and widespread adoption in various fields. Its readability and ease of learning
make it an ideal choice for beginners, enabling students to grasp fundamental
programming concepts effectively. Moreover, Python’s extensive libraries and
frameworks support diverse applications, including data science, web development,
artificial intelligence, and more, aligning with the current industry demands. The
language’s popularity stems from its robust community support, scalability, and cross-
platform compatibility, making it a preferred choice for both educational and
professional purposes. Mastering Python equips students with valuable skills that are
highly sought after in the job market, making it a valuable asset for their academic and
future career endeavours.

QUESTION-2
2. Discuss why python is important to learn for their UG program? Significance of
python. Why python is popular nowadays.
Ans: Python is crucial for undergraduate programs because it's easy to learn, versatile,
and widely used across industries. Its simplicity, rich libraries, community support, and
job opportunities make it an essential skill for students. Python's popularity stems from
its easy learning curve, versatility for various applications, extensive library support,
strong community.
QUESTION-3
3. Introduce them Python Platform (Python Integrated Development Environment).
How it works. Two modes of the platform (GUI, command prompt).
Ans: Python Integrated Development Environment (IDE) is a software application that
provides comprehensive facilities to programmers for software development. It offers
features like code editing, debugging, and execution within a single interface. In the GUI
mode, the IDE provides a graphical user interface where developers can write, edit, and
run Python code efficiently. On the other hand, the command prompt mode allows
users to interact with Python through a command-line interface, providing a more direct
and text-based approach to coding. Both modes have their advantages based on the
developer’s preference and the nature of the project. The GUI mode is user-friendly and
visually interactive, while the command prompt mode offers a more streamlined and
text-focused coding experience. Python IDEs like PyCharm, VS Code, and Jupiter
Notebook are popular choices among developers for their robust features and ease of
use.

QUESTION-4
4. Discuss the alternatives of python (such as R language).
Ans: When considering alternatives to Python, the R language stands out as a powerful
option, particularly in the realm of statistical computing and data analysis. R is renowned
for its extensive libraries and packages tailored for statistical modelling, visualization, and
machine learning. While Python offers versatility across various domains due to its
general-purpose nature, R excels in statistical tasks, making it a preferred choice for
statisticians and data scientists. Both languages have vibrant communities and strong
support, with Python being more versatile for broader applications beyond statistics.
Ultimately, the choice between Python and R depends on the specific requirements of
the project and the expertise of the user.
QUESTION-5
5. Discuss the Course Syllabus, Prerequisites for the Course, Teaching Scheme, List of
Books and Reference Books.
Ans: Python, with its versatility and ease of use, finds applications in various real-life
scenarios. For instance, in data analysis, Python’s libraries like Pandas and NumPy are
extensively used to process and analyse large datasets efficiently. Moreover, in web
development, frameworks like Django and Flask enable developers to build robust web
applications quickly.
Python also plays a significant role in automation tasks. For example, in the finance
sector, Python scripts are utilized for automating repetitive financial calculations and
generating reports. Additionally, in the field of machine learning and artificial intelligence,
Python’s libraries such as TensorFlow and scikit-learn are pivotal for developing advanced
algorithms. In essence, Python’s widespread adoption across industries showcases its
practicality and effectiveness in solving real- world problems.

QUESTION-6
6. Discuss the alternative online python programming platforms (such as Google
Colab, Online Python compilers etc).
Ans: There are several alternative online Python programming platforms available for
users looking to code without setting up a local environment. Google Collab is a popular
choice that offers a Jupyter notebook environment with free access to GPUs. Online
Python compilers like Repl.it and Ide one provides a quick way to run Python code
directly in the browser. Additionally, platforms like PythonAnywhere offer online Python
development environments with features for web hosting and scheduled tasks. Each
platform has its unique features and benefits, catering to different needs and
preferences of Python developers.
QUESTION-8
8. Discuss simple case-study on applications of python in real-life.
Ans: Case Study: Automated Email Scheduler • Problem: Sending regular emails to
clients manually is time consuming and error-prone. • Solution: a.
Data Preparation: Store client information in a CSV file. b. Email Template:
Create a template with placeholders for client-specific details. c. Python Script: Use
Python to read client data, generate personalized emails, and send them automatically.
d. Scheduling: Use Python libraries like `schedule` to schedule the script's execution at
regular intervals. • Benefits: Saves time, reduces errors, and ensures timely
communication with clients.

QUESTION-9
9. Can introduce them elementary operations such as +, -, *, /, % etc python command
prompt.
Ans:
QUESTION-10
OUESTION-11
LAB FILE - 2

QUESTION-1

QUESTION-2
QUESTION-3
QUESTION-4

QUESTION-5
LAB FILE - 3

QUESTION-1
QUESTION-2

QUESTION-3
QUESTION-4
LAB FILE - 4
QUESTION-1
QUESTION-2
QUESTION-4
QUESTION-5
LAB FILE - 5
QUESTION-1

QUESTION-2
QUESTION-3
QUESTION-4
QUESTION-5
LAB FILE – 6
QUESTION-1

QUESTION-2
QUESTION-3
QUESTION-4
QUESTION-5

QUESTION-6
LAB FILE – 7
QUESTION-1
QUESTION-2

QUESTION-3
QUESTION-4
QUESTION-5
LAB FILE – 8

QUESTION-1
1. WAP with class Person definition. Demonstrate the use of following
concepts of object-oriented python through your program.
Object creation
encapsulation
_init_ ()
_str_ ()

Code:
class person:
def init (self, name, age):
self.name=name
self.age=age

def intro(self):
return 'hello my name is ' + self.name + ' and i am ' +
str(self.age)

p=person ("Vini", 19) print (p. intro ()) Output:


2. Inherit class Person in class student. Demonstrate the use of super () and
define a method to demonstrate method overriding.

Code:
class person:
def init (self):
self.value="inside person"

def show(self): print(self.value)


class student(person):
def init (self):
self.value="inside student"

def show(self): print(self.value)


a=person () b=student () a.show ()
b.show ()
Output:
3. Create a class “Employee” with a function “hello_employee ()”. Now,
create an object of the class and demonstrate the function overloading.
When “hello_employee ()” is called without any argument (e.g., none), it
should print only “Hello”, else when called with employee name as
argument, it should print “Hello $Employee Name$”. (Concept: Method
Overloading)

Code:
class employee:
def hello_employee (self, name=None):
if name is None:
print("hello")
else:
print (f"hello {name}")

emp=employee () emp. hello_employee ()


emp. hello_employee("Vini")
Output:
LAB FILE – 9

QUESTION-1
QUESTION-2

2. Create a class “Animal” with attribute “name” and a function “eat ()”.
Now, create another class “Dog”, which inherit the “Animal” class. The
“Dog” class will have a method “Display ()” to print “My name is
$dog_name$”. The eat () method of “Animal” class will print a message “I
can eat”. Now, demonstrate the inheritance by creating an object of class
“Dog”, which will inherit the attribute “name” and method “eat” of
“Animal” class.

Code:
class animal:

def init (self, name):


self.name = name

def eat(self):
print ("I can eat")

class cat(animal): def display(self):


print (f"My name is {self.name}")

class dog(animal): def display(self):


print (f"My name is {self.name}")

cat = cat("furball") dog = dog("oreo") cat. display () cat. eat ()


dog. display ()
dog.eat ()
Output:

QUESTION-3

3. Explain the concept of multiple Inheritance with suitable example.

Multiple inheritance is a feature of object-oriented programming languages


that allows a class to inherit attributes and methods from more than one
parent class. This means that a subclass can inherit behaviors and properties
from multiple parent classes.

Example: class Animal:

def init (self, name):


self.name = name
def speak(self):
raise NotImplementedError ("Subclass must implement
abstract method")

class Dog (Animal):


def speak(self): return "Woof!"

class Cat (Animal): def speak(self): return "Meow!"

class DogCat (Dog, Cat): def init (self, name):


# Multiple inheritance calls for super () might need special care, as the order
matters.

# This example simplifies the behavior to avoid such issues. Super (). init
(name)

pet = DogCat("buddy")
print (pet. Speak ())

Output:
The DogCat class demonstrates multiple inheritance by inheriting from both
Dog and Cat. It inherits the speak method from both parent classes, so when
we create an instance of DogCat and call speak (), it returns "Woof!" because
Dog is listed first in the inheritance list.

4. Explain the concept of multi-level Inheritance with suitable example.

Multi-level inheritance is a feature of object-oriented programming


languages that allows a class to inherit attributes and methods from a parent
class, and then further extend that inheritance to a new subclass. This
creates a hierarchy of classes where each subclass inherits from its
immediate parent class.

Example: class animal:

def init (self, name):


self.name = name

def speak(self):
raise NotImplementedError ("Subclass must implement
abstract method")

class dog(animal):
def speak(self): return "Woof!"

class labrador(dog):

def init (self, name, color):


super (). init (name)
self. color = color

def fetch(self):
return "fetching..."
mylab= labrador ("buddy", "golden") print(mylab.name) print (mylab. color)
print (mylab. speak ())
print (mylab. Fetch ())

Output:

The Animal class is the base class with a name attribute and a speak method.
The Dog class inherits from Animal and implements its own speak method to
return "Woof!". The Labrador class then further extends the Dog class,
inheriting both the speak method from Dog and the name attribute from
Animal. Additionally, Labrador introduces a new attribute color and a new
method fetch.

You might also like