Python
Python
ROLL NO = 23BEC082
BRANCH = ECE
QUESTION-2
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)
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
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
Example:
class Animal:
def init (self, name):
self.name = name
def speak(self):
raise NotImplementedError ("Subclass must implement
abstract method")
pet = DogCat("buddy")
print (pet. Speak ())
Output:
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.