The document contains 7 exercises to practice Python functions:
1. Create a function that takes name and age and prints them.
2. Create a function that accepts a variable number of arguments and prints them.
3. Create a function that returns multiple values - addition and subtraction of inputs.
4. Create a function with a default argument so it can be called with or without that argument.
5. Create nested functions - an inner function inside an outer function to calculate addition.
6. Create a recursive function to calculate the sum from 0 to a given number.
7. Assign a new name to an existing function and call it using the new
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 ratings0% found this document useful (0 votes)
141 views
Python Functions Exercise
The document contains 7 exercises to practice Python functions:
1. Create a function that takes name and age and prints them.
2. Create a function that accepts a variable number of arguments and prints them.
3. Create a function that returns multiple values - addition and subtraction of inputs.
4. Create a function with a default argument so it can be called with or without that argument.
5. Create nested functions - an inner function inside an outer function to calculate addition.
6. Create a recursive function to calculate the sum from 0 to a given number.
7. Assign a new name to an existing function and call it using the new
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
You are on page 1/ 2
Python Functions Exercise Write a program to create function
calculation() such that it can accept two
variables and calculate addition and subtraction. Also, it must return both addition and subtraction in a single return call. Exercise 1: Create a function in Python Exercise 4: Create a function with default argument Write a program to create a function that takes two arguments, name and age, and print their value. Write a program to create a function show_employee() using the following conditions. Exercise 2: Create a function with variable length of arguments It should accept the employee’s name and salary and display both. Write a program to create function func1() to accept a variable length of arguments and print their value. If the salary is missing in the function call then assign default value 9000 to salary Note: Create a function in such a way that we can pass any number of arguments to this function and the function should process them and display each argument’s Exercise 5: Create an inner function to calculate the addition in the following way value. Create an outer function that will accept two parameters, a and b Function call: Create an inner function inside an outer function that will calculate the addition of # call function with 3 arguments a and b func1(20, 40, 60) At last, an outer function will add 5 into addition and return it # call function with 2 arguments Exercise 6: Create a recursive function func1(80, 100) Write a program to create a recursive function to calculate the sum of numbers from 0 to 10. Expected Output: A recursive function is a function that calls itself, again and again. Printing values Expected Output: 20 55 40 Exercise 7: Assign a different name to function and call it through the new name 60 Below is the function display_student(name, age). Assign a new Printing values name show_tudent(name, age) to it and call it using the new name. 80
100
Exercise 3: Return multiple values from a function
Python Advanced Programming: The Guide to Learn Python Programming. Reference with Exercises and Samples About Dynamical Programming, Multithreading, Multiprocessing, Debugging, Testing and More