0% found this document useful (0 votes)
3 views5 pages

SET B Python Programming

The document consists of a Python programming exam with multiple questions covering fundamental concepts such as type casting, operators, data structures (lists, tuples, sets, dictionaries), loops, functions, and constructors. It includes practical programming tasks like swapping variables, generating a Fibonacci series, calculating factorials, and using classes and NumPy for salary calculations and statistical analysis. The exam is structured into sections with varying marks assigned to each question.

Uploaded by

Chetan R Marane
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)
3 views5 pages

SET B Python Programming

The document consists of a Python programming exam with multiple questions covering fundamental concepts such as type casting, operators, data structures (lists, tuples, sets, dictionaries), loops, functions, and constructors. It includes practical programming tasks like swapping variables, generating a Fibonacci series, calculating factorials, and using classes and NumPy for salary calculations and statistical analysis. The exam is structured into sections with varying marks assigned to each question.

Uploaded by

Chetan R Marane
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

SET B Python Programming

Q.1 Attempt all of the following [2 × 10 = 20 Marks]

a) What is type casting? Give one example.


Type casting is converting a value from one data type to another; example:
int("10").

b) Define operators. Name any two arithmetic operators.


Operators are symbols used to perform operations on values; examples: +, -.

c) Define a set.
A set is an unordered collection of unique elements.

d) What is a loop? Name two types.


A loop repeats a block of code; types: for loop, while loop.

e) Define a function.
A function is a reusable block of code that performs a specific task.

f) What is a return value in a function?


A return value is the output a function sends back using return.

g) What is a constructor?
A constructor is a special method that initializes an object when created.

h) What is a NumPy array?


A NumPy array is a multidimensional structure for efficient numerical
computation.

i) What is a tuple?
A tuple is an ordered, immutable collection of elements.

j) What is a list?
A list is an ordered, mutable collection of elements.

k) What is a dictionary?
A dictionary is a collection of key–value pairs.

l) What is an if statement?
An if statement executes code based on a condition.

Q.2 Attempt all of the following [2 × 5 = 10 Marks]

a) Explain lists, tuple, set, and dictionary with differences.

List: Ordered, mutable collection allowing duplicates.


Tuple: Ordered, immutable collection allowing duplicates.

Set: Unordered, mutable collection with unique elements only.

Dictionary: Unordered collection of key–value pairs with unique keys.

Difference: Lists and tuples maintain order; tuples are immutable. Sets
enforce uniqueness. Dictionaries store mapped pairs.

b) Explain if-elif-else with example.

Used for conditional decision-making with multiple conditions

marks = 75

if marks >= 90:

print("Grade A")

elif marks >= 50:

print("Grade B")

else:

print("Fail")

c) Explain for loop and while loop with examples

For loop: Iterates over a sequence for a fixed number of times.

for i in range(5):

print(i)

While loop: Repeats as long as a condition is TRUE.

i=0

while i < 5:

print(i)

i += 1
Q.3 Attempt any TWO of the following [2 × 5 = 10 Marks]

a) Write a Python program to swap two variables.

a = int(input("Enter first value: "))

b = int(input("Enter second value: "))

a, b = b, a

print("After swapping:")

print("a =", a)

print("b =", b)

b) Write a Python program to print Fibonacci series (10 terms).

n = 10

a, b = 0, 1

for i in range(n):

print(a, end=" ")

a, b = b, a + b

c) Write a Python program to find factorial using a function.

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

fact = 1

for i in range(1, num + 1):

fact *= i

print("Factorial:", fact)
Q.4 Attempt any TWO of the following [2 × 5 = 10 Marks]

a) Write a Python program using a class to calculate salary with bonus.

class Salary:

def __init__(self, basic, bonus_percent):

[Link] = basic

self.bonus_percent = bonus_percent

def total_salary(self):

bonus = [Link] * self.bonus_percent / 100

return [Link] + bonus

basic = float(input("Enter basic salary: "))

bonus_percent = float(input("Enter bonus percent: "))

emp = Salary(basic, bonus_percent)

print("Total Salary:", emp.total_salary())

b) Write a NumPy program to find mean, maximum, and minimum of an

array

import numpy as np

arr = [Link]([10, 25, 35, 50, 75])

print("Mean:", [Link]())

print("Maximum:", [Link]())

print("Minimum:", [Link]())
. c) Write a Python program to calculate area of rectangle and circle.

import math

length = float(input("Enter length: "))

width = float(input("Enter width: "))

radius = float(input("Enter radius: "))

rectangle_area = length * width

circle_area = [Link] * radius * radius

print("Area of Rectangle:", rectangle_area)

print("Area of Circle:", circle_area)

You might also like