Python
Python
Answer:
Answer:
1. Interactive Mode: Best for quick tests and immediate feedback. It is accessed through the
command line and is excellent for learning, debugging, and exploring Python features.
2. Script Mode: Ideal for writing, saving, and running complete programs. It allows for better
organization, reuse, and maintenance of code, suitable for larger projects and applications.
Answer:
A list is a versatile and mutable data structure used to store a collection of elements. Lists are
ordered, meaning the elements are stored in a specific sequence and can be accessed by their index.
A list in Python is defined by enclosing a sequence of elements within square brackets [ ].
1d. give a command to print out the list, and hence state the expected output for the list
Answer:
To print out the given list in Python, you can use the print() function. Here's the command to print
the list:
print(List1)
Expected Output:
[1, 2, 3, 'A', 'B', 7, 8, [10, 11]]
1e. write a python program to print all the month in a year 2022
Answer:
import calendar
def print_months(year):
month_name = calendar.month_name[month]
print(month_name)
print_months(2022)
Answer:
Output1: 64
Output2: 8.0
Output3: 3.142
Output4: 30
1g. given an array of numbers: [5,10,25], write a python code to display the lowest and the
highest out of the three numbers
Answer:
lowest = min(numbers)
highest = max(numbers)
Answer:
Yes, Python is an Object-Oriented Programming (OOP) language. It supports and encourages the
use of object-oriented programming principles. Below is Python's OOP features:
1. Class and Object Concept: Python allows the creation of classes and objects, which are
fundamental concepts of OOP. Classes serve as blueprints for creating objects, while
objects are instances of classes.
2. Encapsulation: Encapsulation refers to the bundling of data and methods that operate on
the data within a single unit (i.e., a class). Python supports encapsulation through the use
of classes.
3. Inheritance: Inheritance is the mechanism by which a class can derive properties and
behaviors from another class. Python supports single inheritance, where a class can inherit
from one parent class.
4. Polymorphism: Polymorphism allows objects of different classes to be treated as objects
of a common superclass. Python supports polymorphism through method overriding and
duck typing.
5. Abstraction: Abstraction refers to the concept of hiding complex implementation details
and showing only the necessary features of an object. Python supports abstraction through
classes and methods.
2b. juxtapose (2) between procedure oriented programming and object oriented
programming language
Answer:
Answer:
Answer:
2e. write a python program which accepts the radius of a circle from a user and computed
the area.
Answer:
import math