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

Session 5 ITP Lab Ques

questions on python on classes

Uploaded by

Anita
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 views2 pages

Session 5 ITP Lab Ques

questions on python on classes

Uploaded by

Anita
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/ 2

Introduction to Programming

Session - 5
Functions

Q.1. Write a function update_list that takes a list and an integer as parameters. The
function should append the integer to the list and return the updated list. Demonstrate
how variable scope affects the original list outside the function.

Q.2. Create a recursive function factorial(n) that computes the factorial of a


non-negative integer n. Include base cases to handle n=0 and n=1. %recursive function

Q.3. Write a program that uses map() to square each number in a given list and
filter() to keep only those squares that are greater than 10. Use lambda functions for
both operations. %map(), lambda()

Q.4. Create a function calculate_area() that takes a parameter radius and defines a local
variable area to calculate the area of a circle. Outside this function, define a global
variable area with a different value. After calling the function, print both the local and
global area variables to demonstrate variable shadowing. %variable scope; global and
local variables

Q.5. You are developing a simple game where players can earn points. Write a recursive
function calculate_points(level) that returns the total points earned by a player at a given
level. The points for each level are defined as follows: Level 1 earns 10 points, Level 2
earns 20 points, Level 3 earns 30 points, and so on (10 points per level). %recursive
function

Q.6. You are analyzing student grades. Write a program that uses map() to convert a list
of grades (out of 100) into their corresponding letter grades (A, B, C, D, F). A implies
90-100, b implies 80-90 and so on. Use filter() to keep only those students who received
an A grade. Let the students' marks be 95, 82, 76, 88 and 60.%map(), filter()
#Concept: map() transforms data while filter() selects specific data based on
conditions.

Q.7. Write a program that uses reduce() to flatten a nested list (a list of lists) into a
single list. For example, given [[1, 2], [3], [4, 5]], the output should be [1, 2, 3, 4, 5].
%reduce()
Q.8. Create a function update_scores(scores_dict) that takes a dictionary of student
scores and increases each score by a specified amount. Return the updated dictionary.

Q.9. Implement a generator function custom_range(start, end) that behaves like the
built-in range() function but allows for floating-point increments. For example,
custom_range(1.0, 5.0, 0.5) should yield values from 1.0 to 4.5.

Q.10. Write a generator function arithmetic_progression(start, step) that yields an


arithmetic progression starting from start with a common difference of step. For
example, calling arithmetic_progression(5, 2) should yield values like 5, 7, 9, etc.

You might also like