0% found this document useful (0 votes)
16 views

Python

Uploaded by

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

Python

Uploaded by

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

QUESTION ONE

1a. state four factors of using python in day-to-day life

Answer:

1. Ease of Learning and Use


2. Versatility and Flexibility
3. Robust Libraries and Frameworks
4. Automation and Scripting

1b. what are two modes of using python interpreter

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.

1c. in details explain the term list in python programming

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:

List1 = [1, 2, 3, 'A', 'B', 7, 8, [10, 11]]

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):

for month in range(1, 13):

month_name = calendar.month_name[month]

print(month_name)

print_months(2022)

1f. what will be the output of the following codes below

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:

numbers = [5, 10, 25]

lowest = min(numbers)

highest = max(numbers)

print("Lowest number:", lowest)

print("Highest number:", highest)


QUESTION TWO

2a. is python an object oriented programming (oop)? Discuss.

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:

Procedure-Oriented Programming (POP):

1. POP focuses on functions (procedures) to operate on data.


2. Programs are designed around functions or procedures which perform operations on data.
Object-Oriented Programming (OOP):

1. OOP focuses on objects which combine data and methods.


2. Programs are designed around objects which encapsulate both data and the functions that
operate on that data.

2c. explain the programming applications of Object-Oriented Programming (OOP)

Answer:

1. Graphical User Interface (GUI) Development: OOP is extensively used in GUI


development to create interactive and user-friendly interfaces.
2. Web Development: OOP plays a significant role in web development, enabling the creation
of modular and scalable web applications.
3. Game Development: OOP is widely used in game development to model game entities,
behaviors, and interactions.
4. Enterprise Applications: OOP is widely used in enterprise application development to build
scalable and maintainable software solutions.
5. Data Science and Machine Learning: OOP is employed in data science and machine
learning applications to organize and manipulate data efficiently.

2d. highlight four benefits of Object-Oriented Programming (OOP)

Answer:

1. Modularity and Reusability.

2. Encapsulation and Information Hiding.

3. Inheritance and Code Reuse.

4. Polymorphism and Flexibility.

2e. write a python program which accepts the radius of a circle from a user and computed
the area.

Answer:
import math

radius = float(input("Enter the radius of the circle: "))

area = math.pi * radius ** 2

print("The area of the circle with radius", radius, "is:", area)

You might also like