SET A Python Programming
Q.1 Attempt any TEN of the following [2 × 10 = 20 Marks]
a) What is Python? Mention one feature.
Python is a high-level programming language; feature: simple and readable syntax.
b) What is Anaconda?
Anaconda is a Python distribution that includes packages and tools for data science.
c) What is Jupyter Notebook?
Jupyter Notebook is an interactive environment for writing and running code with
outputs.
d) What is the difference between input() and print()?
input() reads user input; print() displays output.
e) List four basic data types in Python.
Integer, Float, String, Boolean.
f) What is a string?
A string is a sequence of characters enclosed in quotes.
g) What is indexing in lists?
Indexing accesses elements using their position number starting from 0.
h) Difference between list and tuple.
Lists are mutable; tuples are immutable.
i) What is a dictionary?
A dictionary is a collection of key–value pairs.
j) What is a function in Python?
A function is a reusable block of code that performs a task.
k) What is a class in Python?
A class is a blueprint for creating objects with attributes and methods.
l) What is NumPy?
NumPy is a Python library used for numerical computing and array operations.
Q.2 Attempt any TWO of the following [2 × 5 = 10 Marks]
a) Explain Python data types with examples.
Python data types define the kind of value a variable can store. Common types include:
Integer (int): Whole numbers. Example: x = 10
Float (float): Decimal numbers. Example: y = 3.14
String (str): Sequence of characters. Example: name = "Python"
Boolean (bool): Logical values. Example: flag = True
List (list): Ordered, mutable collection. Example: nums = [1,2,3]
Tuple (tuple): Ordered, immutable collection. Example: coords = (10,20)
Dictionary (dict): Key–value pairs. Example: student = {"Name":"Alex","Age":21}
b) Explain operators in Python with examples.
Operators perform operations on variables and values.
Arithmetic: +, -, *, /. Example: a + b
Comparison: ==, !=, >, <. Example: x > y
Logical: and, or, not. Example: x > 5 and y < 10
Assignment: =, +=, -=. Example: x += 2
Membership: in, not in. Example: "a" in name
c) Explain string functions (upper(), lower(), replace()) with examples.
upper(): Converts text to uppercase. Example: "python".upper() → "PYTHON"
lower(): Converts text to lowercase. Example: "DATA".lower() → "data"
replace(): Replaces part of a string. Example: "Hello World".replace("World","Python") →
"Hello Python"
Q.3 Attempt any TWO of the following [2 × 5 = 10 Marks]
a) Write a Python program to add and subtract two numbers.
a = float(input("Enter first number: "))
b = float(input("Enter second number: "))
print("Addition:", a + b) print("Subtraction:", a - b)
b) Write a Python program to check whether a number is even or odd.
num = int(input("Enter a number: "))
if num % 2 == 0:
print("Even")
else:
print("Odd")
c) Write a Python program to demonstrate string slicing and find maximum
element from a list
text = input("Enter a string: ")
print("First 3 characters:", text[:3])
print("Last 3 characters:", text[-3:])
print("Reversed string:", text[::-1])’
numbers = [10, 45, 23, 89, 12]
print("List:", numbers)
print("Maximum element:", max(numbers))
Q.4 Attempt any TWO of the following [2 × 5 = 10 Marks]
a) Explain functions in Python with parameters and return values.
In Python, functions are reusable blocks of code that perform specific tasks. They
use parameters to accept input data and the return statement to send results back
to the caller
Parameters vs. Arguments
● Parameters are the variables defined in the function definition (e.g.,
parameter1, parameter2 in the syntax above) that act as placeholders for the
input.
● Arguments are the actual values passed to the function when it is called
b) Write a Python program to create a dictionary and display keys
and values.
data = {"Name": "Rahul", "Age": 21, "Course": "Data Science"}
print([Link]())
print([Link]())
c) Write a Python program to create a 3×3 NumPy array and find
row-wise sum.
import numpy as np
arr = [Link]([[1,2,3],[4,5,6],[7,8,9]])
print([Link](axis=1))