Python Functions


1) Simple Function

Define a function hello() that prints:

Hello, World!

Call it.


2) Function with No Return

Write a function greet(name) that prints:

Hello, <name>!

Ask user input and pass it to the function.


3) Add Two Numbers

Write add(a, b) that returns the sum of two numbers. Test it with user input.


4) Multiply Two Numbers

Write multiply(x, y) that returns the product.


5) Function with Default Argument

Define:

Print msg. Call it with and without argument.


6) Function to Find Square

Create square(n) that returns n * n.


7) Area of Rectangle

Write area(length, breadth) and return the area.


8) Function to Check Even

Create is_even(num) that returns True if even, else False.


9) Function to Return Max

Write max_of_two(a, b) that returns the larger number.


10) Function to Count Characters

Write count_chars(s) that returns the number of characters in a string.


11) Function with No Parameters

Create print_separator() that prints a line of dashes:


12) Function to Print List Items

Write a function print_list(lst) that prints each element of the list.


13) Convert Celsius to Fahrenheit

Write to_fahrenheit(c) that returns:


14) Function to Reverse String

Define reverse_string(s) and return reversed string.


15) Function to Check Vowel

Write is_vowel(ch) that returns True if ch is a vowel.


16) Function to Print Multiplication Table

Write print_table(n) that prints multiplication table of n up to 10.


17) Function with Return and Print

Write cube(n) returning the cube of a number. Print the returned value.


18) Function to Sum List

Write sum_list(nums) that returns the total of list items.


19) Function to Find Factorial

Write factorial(n) that returns factorial using a loop.


20) Function to Greet Multiple People

Write:

Loop and print:

for each.


📝 Notes for Students

  • Define a function with:

  • Return values with return.

  • You can have default, positional, and *variable (e.g., args) parameters.


canvil: 333f6c7d-6876-4f7e-b6ad-1bdb2233f5c1

Last updated