0% found this document useful (0 votes)
10 views10 pages

Python Exp 6

The document outlines an experiment in Python programming focused on functions, recursion, and lambda expressions. It includes specific tasks such as finding maximum and minimum values, calculating sums of cubes, and working with dictionaries. The learning outcomes emphasize developing user-defined functions, applying recursion, and enhancing problem-solving skills in Python.

Uploaded by

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

Python Exp 6

The document outlines an experiment in Python programming focused on functions, recursion, and lambda expressions. It includes specific tasks such as finding maximum and minimum values, calculating sums of cubes, and working with dictionaries. The learning outcomes emphasize developing user-defined functions, applying recursion, and enhancing problem-solving skills in Python.

Uploaded by

abhinavbhattuk
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

NAME – ABHINAV BHATT

SAP ID – 590025991
BATCH – 26

PYTHON PROGRAMMING
Experiment 6
AIM: Functions

1. Write a Python function to find the maximum and minimum numbers


from a

sequence of numbers. (Note: Do not use built-in functions.)

2. Write a Python function that takes a positive integer and returns the
sum of the

cube of all the positive integers smaller than the specified number.

3. Write a Python function to print 1 to n using recursion. (Note: Do not


use loop)

4. Write a recursive function to print Fibonacci series upto n terms.

5. Write a lambda function to find volume of cone.

6. Write a lambda function which gives tuple of max and min from a list.

Sample input: [10, 6, 8, 90, 12, 56]

Sample output: (90,6)

78

7. Write functions to explain mentioned concepts:

a. Keyword argument

b. Default argument

c. Variable length argument

8. Write a program to check whether all the values in a dictionary are


same or not

using lambda function.

9. Write a program to create two lists and generate a dictionary with keys
from

list1 and values from list2.


Theory
This experiment focuses on understanding fundamental and intermediate
concepts of Python programming, including functions, recursion, lambda
expressions, and data structures like lists and dictionaries.

A function in Python is a reusable block of code that performs a specific


task. Functions improve modularity and code readability. In this
experiment, user-defined functions are implemented to solve problems
such as finding maximum and minimum values from a sequence without
using built-in functions, and calculating mathematical results like the sum
of cubes.

Recursion is an important concept where a function calls itself to solve


smaller instances of a problem. It is used here to print numbers from 1 to
n and to generate the Fibonacci series. Recursion helps in solving
problems that can be broken down into similar subproblems.

Lambda functions are small anonymous functions defined using the


lambda keyword. They are useful for short operations and are often used
where a function is required temporarily. In this experiment, lambda
functions are used to compute the volume of a cone and to find maximum
and minimum values from a list.

Different types of function arguments are also explored:

 Keyword arguments allow passing values by specifying parameter


names.

 Default arguments provide default values to parameters if no


argument is supplied.

 Variable-length arguments allow functions to accept an arbitrary


number of arguments.

The experiment also covers dictionary operations, including checking


whether all values in a dictionary are the same using lambda functions,
and creating a dictionary by combining two lists (keys and values). These
concepts demonstrate how Python handles data collections efficiently.

Overall, the experiment builds a strong foundation in problem-solving


using Python functions and data structures.
PYTHON CODE:
1)

OUTPUT:
2)

OUTPUT:
3)

OUTPUT:
4)

OUTPUT:

5)

OUTPUT:
6)

OUTPUT:
7)

OUTPUT:
Learning Outcomes
After completing this experiment, the learner will be able to:
1. Develop user-defined functions to solve problems without relying on
built-in functions.
2. Apply recursion to solve problems such as number printing and
Fibonacci series generation.
3. Understand and implement lambda (anonymous) functions for
concise operations.
4. Differentiate between keyword, default, and variable-length
arguments in Python functions.
5. Perform operations on lists, such as finding maximum and minimum
values.
6. Work with dictionaries, including checking value uniformity and
creating dictionaries from lists.
7. Enhance logical thinking and problem-solving skills using Python
programming.
8. Write efficient and modular Python programs using functions and
recursion.

You might also like