[go: up one dir, main page]

0% found this document useful (0 votes)
8 views17 pages

QB Solved

The document outlines various features of Python, including its open-source nature, ease of coding, and support for object-oriented programming. It also discusses problem-solving steps, programming paradigms, and modularization, along with examples of Python programs for tasks like checking voting eligibility and calculating the sum of digits. Additionally, it explains list operations, selection statements, and dictionary manipulations.

Uploaded by

sakpalsarthak30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views17 pages

QB Solved

The document outlines various features of Python, including its open-source nature, ease of coding, and support for object-oriented programming. It also discusses problem-solving steps, programming paradigms, and modularization, along with examples of Python programs for tasks like checking voting eligibility and calculating the sum of digits. Additionally, it explains list operations, selection statements, and dictionary manipulations.

Uploaded by

sakpalsarthak30
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Q1.Explain any six features of python.

Features in Python
In this section we will see what are the features of Python programming language:

1. Free and Open Source


Python language is freely available at the official website and you can download it from the
given download link below click on the Download Python keyword. Download Python Since it
is open-source, this means that source code is also available to the public. So you can download
it, use it as well as share it.

2. Easy to code
Python is a high-level programming language. Python is very easy to learn the language as
compared to other languages like C, C#, Javascript, Java, etc. It is very easy to code in the
Python language and anybody can learn Python basics in a few hours or days. It is also a
developer-friendly language.

3. Easy to Read
As you will see, learning Python is quite simple. As was already established, Python’s syntax is
really straightforward. The code block is defined by the indentations rather than by semicolons
or brackets.

4. Object-Oriented Language
One of the key features of Python is Object-Oriented programming. Python supports
object-oriented language and concepts of classes, object encapsulation, etc.

5. GUI Programming Support


Graphical User interfaces can be made using a module such as PyQt5, PyQt4, wxPython, or Tk
in Python. PyQt5 is the most popular option for creating graphical apps with Python.

6. High-Level Language
Python is a high-level language. When we write programs in Python, we do not need to
remember the system architecture, nor do we need to manage the memory.
7. Large Community Support
Python has gained popularity over the years. Our questions are constantly answered by the
enormous StackOverflow community. These websites have already provided answers to many
questions about Python, so Python users can consult them as needed.

8. Easy to Debug
Excellent information for mistake tracing. You will be able to quickly identify and correct the
majority of your program’s issues once you understand how to interpret Python’s error traces.
Simply by glancing at the code, you can determine what it is designed to perform.

9. Python is a Portable language


Python language is also a portable language. For example, if we have Python code for Windows
and if we want to run this code on other platforms such as Linux, Unix, and Mac then we do not
need to change it, we can run this code on any platform.

10. Python is an Integrated language


Python is also an Integrated language because we can easily integrate Python with other
languages like C, C++, etc.

11. Interpreted Language:


Python is an Interpreted Language because Python code is executed line by line at a time. like
other languages C, C++, Java, etc. there is no need to compile Python code this makes it easier to
debug our code. The source code of Python is converted into an immediate form called bytecode.

12. Large Standard Library


Python has a large standard library that provides a rich set of modules and functions so you do
not have to write your own code for every single thing. There are many libraries present in
Python such as regular expressions, unit-testing, web browsers, etc.

******************************************************************************
****
Q.2What is problem ? List down steps in problem solving with suitable example
A problem is a situation or challenge that requires a solution. It arises when there is a gap
between the current state and the desired goal, and there is uncertainty about how to bridge that
gap.
Steps in Problem Solving
The problem-solving process involves systematic steps to analyze and resolve an issue
effectively. The main steps are:

1. Identify the Problem


●​ Clearly define the problem.
●​ Understand its nature and scope.
●​ Example: A company is facing declining sales.

2. Analyze the Problem


●​ Gather relevant information.
●​ Identify possible causes.
●​ Example: The company investigates reasons for the decline—competition, pricing, or
marketing strategies.

3. Generate Possible Solutions


●​ Brainstorm different solutions.
●​ Consider both conventional and creative approaches.
●​ Example: The company considers solutions like reducing prices, improving product
quality, or enhancing marketing efforts.

4. Evaluate and Select the Best Solution


●​ Compare possible solutions based on feasibility, cost, and effectiveness.
●​ Choose the most practical and impactful option.
●​ Example: The company decides to launch a new advertising campaign to attract
customers.

5. Implement the Solution


●​ Develop an action plan.
●​ Assign responsibilities and execute the solution.
●​ Example: The company launches a social media and television ad campaign.

6. Monitor and Review the Outcome


●​ Evaluate the results to see if the problem is resolved.
●​ Make necessary adjustments if needed.
●​ Example: The company tracks sales data and customer feedback to measure the impact of
the new marketing strategy.
******************************************************************************
*******
Q.3Program to determine whether a person is eligible to vote or not.
# Program to check voting eligibility

# Get age input from the user


age = int(input("Enter your age: "))

# Check voting eligibility


if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")
******************************************************************************
*****
Q.4.Program to print multiplication table of n where n value is entered by user

​ ​ ​ # Get user input


n = int(input("Enter a number: "))

# Print multiplication table


print(f"Multiplication Table of {n}:")
for i in range(1, 11):
print(f"{n} x {i} = {n * i}")

******************************************************************************
*******
Q.What is modularization ? Explain top down design approach.

Modularization
Modularization is the process of dividing a large program into smaller, manageable, and
independent modules or functions. Each module performs a specific task and can be developed,
tested, and debugged independently before being integrated into the main program. This
approach improves code readability, reusability, maintainability, and efficiency.

Top-Down Design Approach


The Top-Down Design Approach (also called Stepwise Refinement) is a programming and
problem-solving methodology that starts with a high-level overview of a system and breaks it
down into smaller, detailed components.
Steps in the Top-Down Design Approach
1.​ Identify the Main Problem: Define the overall objective of the system.
2.​ Divide into Subproblems: Break down the problem into smaller, manageable modules.
3.​ Further Decomposition: Continue breaking down modules until each module is simple
enough to be implemented directly.
4.​ Implement and Test: Implement the modules separately and test them independently.
5.​ Integrate the Modules: Combine all the modules to form the complete system.

Example of Top-Down Design


Consider developing a library management system:
1.​ Main Functionality: Manage library operations.
2.​ Submodules:
○​ User Management (Add, Remove, Update users)
○​ Book Management (Add, Remove, Search books)
○​ Borrow/Return System (Issue, Return, Fine Calculation)
3.​ Further Breakdown:
○​ User Management → Add User, Remove User, Update User Details
○​ Book Management → Search by Title, Author, ISBN
○​ Borrow System → Check Availability, Assign Book, Calculate Due Date

Dig.Top-Down Design Approach

******************************************************************************
*******
Q.Define Programming Paradigm?List programming Paradigm?Explain one in detail.

Definition of Programming Paradigm


A programming paradigm is a fundamental style or approach to programming that provides a
structured way to design and implement software solutions. It defines the principles, concepts,
and methodologies used in writing programs. Different paradigms offer various ways to think
about and solve problems in programming.
List of Programming Paradigms
Programming paradigms can be categorized into several types, including:
1.​ Imperative Paradigm​

○​ Procedural Programming
○​ Object-Oriented Programming (OOP)
○​ Parallel Programming
2.​ Declarative Paradigm​

○​ Functional Programming
○​ Logic Programming
○​ Database Query Programming (SQL)
3.​ Event-Driven Paradigm​

4.​ Concurrent and Parallel Paradigm​

Explanation of Object-Oriented Programming (OOP) in Detail


Object-Oriented Programming (OOP) is an imperative programming paradigm that organizes
software design around objects rather than functions or logic.

Key Concepts of OOP:


1.​ Class: A blueprint or template for creating objects. It defines the properties (attributes)
and behaviors (methods) of objects.
2.​ Object: An instance of a class that contains data and methods to manipulate that data.
3.​ Encapsulation: The concept of restricting access to certain details of an object and only
exposing the necessary parts.
4.​ Abstraction: Hiding the complex implementation details and only showing the essential
features.
5.​ Inheritance: A mechanism that allows a new class (child) to inherit properties and
behavior from an existing class (parent).
6.​ Polymorphism: The ability of different objects to respond to the same function call in
different ways.
Advantages of OOP:
●​ Code reusability through inheritance.
●​ Modularity and better code organization.
●​ Scalability and ease of maintenance.
●​ Encourages real-world modeling.
******************************************************************************
*****

Q.Write a program to swap two numbers

# Swap two numbers using a temporary variable


a = int(input("Enter first number: "))
b = int(input("Enter second number: "))

print(f"Before swapping: a = {a}, b = {b}")

# Swapping
temp = a
a=b
b = temp
print(f"After swapping: a = {a}, b = {b}")

******************************************************************************
*******
Q.Program to enter a number and then calculate the sum of its digits

# Program to calculate the sum of digits of a number

# Taking input from the user


num = int(input("Enter a number: "))

# Initialize sum to 0
sum_digits = 0

# Loop to extract and sum digits


while num > 0:
sum_digits += num % 10 # Extract last digit and add to sum
num //= 10 # Remove last digit

# Display the result


print("Sum of digits:", sum_digits)
******************************************************************************
**
Q.What is dictionary ?How to add and remove elements in dictionary?

What is a Dictionary in Python?


A dictionary in Python is an unordered collection of key-value pairs. Each key is unique, and it is
used to access its corresponding value. Dictionaries are defined using curly brackets {}.

Example of a Dictionary:

student = {
"name": "Alice",
"age": 22,
"course": "Computer Science"
}
print(student)
Output:

{'name': 'Alice', 'age': 22, 'course': 'Computer Science'}

How to Add Elements to a Dictionary?

1. Using Assignment (dict[key] = value)


You can add a new key-value pair or update an existing one.
student["grade"] = "A" # Adding a new key-value pair
print(student)

Output:

{'name': 'Alice', 'age': 22, 'course': 'Computer Science', 'grade': 'A'}

How to Remove Elements from a Dictionary?

1. Using del Statement


Removes a specific key-value pair.
del student["age"]
print(student)

Output:

{'name': 'Alice', 'course': 'Computer Science', 'grade': 'A', 'city': 'New York', 'ID': 101}

2. Using pop() Method


Removes and returns the value of the specified key.

removed_value = student.pop("course")
print(student)
print("Removed Value:", removed_value)

Output:
{'name': 'Alice', 'grade': 'A', 'city': 'New York', 'ID': 101}
Removed Value: Computer Science
******************************************************************************
******
Q.Explain Selection /Condition Statements in python

Selection (Conditional) Statements in Python


Selection or conditional statements in Python allow a program to make decisions and execute
different blocks of code based on certain conditions. Python provides the following types of
selection statements:

1. if Statement
The if statement checks a condition and executes a block of code only if the condition is True.

Syntax:

if condition:
# Code to execute if the condition is True

Example:
python
CopyEdit
age = 18
if age >= 18:
print("You are eligible to vote.")

Output:

You are eligible to vote.


2. if-else Statement
The if-else statement provides an alternative block of code to execute if the condition is False.

Syntax:

if condition:
# Code to execute if condition is True
else:
# Code to execute if condition is False

Example:

age = 16
if age >= 18:
print("You are eligible to vote.")
else:
print("You are not eligible to vote.")

Output:

You are not eligible to vote.

3. if-elif-else Statement (Multiple Conditions)


The if-elif-else statement allows checking multiple conditions one after another.

Syntax:

if condition1:
# Code if condition1 is True
elif condition2:
# Code if condition2 is True
else:
# Code if none of the conditions are True
Example:

marks = 85

if marks >= 90:


print("Grade: A")
elif marks >= 75:
print("Grade: B")
elif marks >= 60:
print("Grade: C")
else:
print("Grade: F")

Output:

Grade: B

******************************************************************************
*******
Q.Write a program to find whether entered no is Armstrong or not

num = int(input("Enter a number: ")) # Taking input from the user


temp = num
sum_of_digits = 0
num_of_digits = len(str(num)) # Counting the number of digits

while temp > 0:


digit = temp % 10 # Extracting the last digit
sum_of_digits += digit ** num_of_digits # Raising it to the power of the number of digits
temp //= 10 # Removing the last digit

if sum_of_digits == num:
print(f"{num} is an Armstrong number")
else:
print(f"{num} is not an Armstrong number")

******************************************************************************
*******
QWrite a program to find whether entered character is vowel or not
char = input("Enter a character: ") # Taking input from the user

# Checking if the entered character is a vowel


if char in 'AEIOUaeiou':
print("The entered character is a vowel.")
else:
print("The entered character is not a vowel.")
******************************************************************************
*******Q.Describe the following term with examples
1)​ break 2)continue 3)pass 4)range()

1) break
The break statement is used to exit a loop prematurely when a certain condition is met. It stops
the loop entirely.

Example:
for num in range(1, 6):
if num == 3:
break # Exits the loop when num is 3
print(num)

Output:
1
2

The loop stops when num reaches 3.

2) continue
The continue statement is used to skip the rest of the current iteration and move to the next
iteration of the loop.

Example:
for num in range(1, 6):
if num == 3:
continue # Skips printing 3 and moves to the next iteration
print(num)
Output:
1
2
4
5

The number 3 is skipped, but the loop continues.

3) pass
The pass statement is a placeholder that does nothing. It is used when a statement is syntactically
required but no action is needed.

Example:
for num in range(1, 6):
if num == 3:
pass # Does nothing, loop continues normally
print(num)

Output:

1
2
3
4
5

The loop continues normally, as pass does nothing.

4) range()
The range() function generates a sequence of numbers. It is commonly used in loops.

Example 1: Basic range


for num in range(5):
print(num)

Output:
0
1
2
3
4

(Default start is 0, end is 5 (exclusive), step is 1)

Example 2: Specifying start and stop


for num in range(2, 7):
print(num)

Output:

2
3
4
5
6
*****************************************************************************
Q.Explain following operations of list
1)creating a list 2)Display list 3)Appending 4)Accessing an elements

Operations on a List in Python

1) Creating a List
A list in Python can be created using square brackets [], with elements separated by commas.
Example:

# Creating a list of numbers


numbers = [1, 2, 3, 4, 5]

# Creating a list with different data types


mixed_list = [10, "hello", 3.5, True]

2) Displaying a List
You can display a list using the print() function.
Example:
fruits = ["apple", "banana", "cherry"]
print(fruits) # Output: ['apple', 'banana', 'cherry']

You can also display each element using a loop:


python

for fruit in fruits:


print(fruit)

3) Appending an Element
To add an element at the end of a list, use the append() method.
Example:

fruits.append("orange")
print(fruits) # Output: ['apple', 'banana', 'cherry', 'orange']

4) Accessing Elements
Elements in a list can be accessed using their index. Python uses zero-based indexing (i.e., the
first element is at index 0).
Example:

print(fruits[0]) # Output: apple


print(fruits[2]) # Output: cherry

Negative indexing allows access from the end:

print(fruits[-1]) # Output: orange (last element)


print(fruits[-2]) # Output: cherry
******************************************************************************
*******
Q.write a python program to display the star pattern as
*
**
***
for i in range(0,3):
for j in range(0, i+1):
print("*", end='')
print()

******************************************************************************
******
Q.Write a program to find if number is divisible by 7
# Taking user input
num = int(input("Enter a number: "))

# Checking divisibility
if num % 7 == 0:
print(f"{num} is divisible by 7.")
else:
print(f"{num} is not divisible by 7.")

You might also like