Questions on Functions in Python

functions in Python

  1. Create a function to print Welcome ( without any return data to main body )
  2. Create a function to display sum of two integers, print should be inside the function.
  3. Create a function to display square of 5 ( without any return data to parent script )
  4. Take one user input number and pass it to a function to display the same by adding 10 to its value.
  5. Create a function to return square of 5 to parent function and then display by using print.
  6. Create a function to receive number 5 as parameter and return square of it to main script. Display the return value using print inside main script .
  7. Ask user to enter one number and then use the function to display square of it inside the function without returning any data to calling script.
  8. Ask user to enter one number, pass this number to a function, return the number to main script after adding 10 to the value.
  9. Ask the user to input two numbers and display the sum of it ( without using any function )
  10. Ask the user to input two numbers and display the sum of it inside a function ( without returning any data to main script )
  11. Ask for two user input numbers, pass to a function and then display highest number.
  12. Ask for two user input numbers, pass to a function and then return highest number to main function.
  13. Ask for two user input numbers, pass to a function and then return highest number to main function. Display the highest number inside main function.
  14. Ask the user to input two numbers and return the sum to main script by using a function and then inside the main display the result after multiplying the sum by 2.
  15. Ask user to enter three numbers then pass the value to a function. Add three numbers inside the function and return the result to main function. Inside main function display the result by adding 10 to it.
  16. Enter your car number ( only number part ) , then enter day number starting from 1 to 7 ( day number of the week ). Your program should say you should go out in your car or not. All even day numbers are mean for cars with even numbers and odd car numbers are for odd day numbers.
  17. Declare a variable num1 equal to 5 inside main script. Create one more function my_fun() and display the value of num1 inside it. ( Don’t declare num1 again inside the my_fun() )
  18. Declare a variable num1 equal to 5 inside main() function. Create one function my_fun() and declare variable num1 equal to 100 and display the value of num1 inside it. Check the output.
  19. In above code , add 100 to num1 after declaring inside my_fun() and display the value.
  20. In above code call the function two times in main function and check the value it displays.
  21. How the value will change in above code if you declare num1 as static variable.
  22. Find out the lowest common factor ( LCF ) of two input numbers.
  23. Find out highest common factor ( HCF ) or greatest common factor of two input numbers.
Find the solutions by using recursive functions
  1. User input one positive integer n, Create a function to find sum of all numbers upto n.
    Sum = n+(n-1)+(n-2)… +2+1+0
  2. Find the factorial of a input positive number. ( Factorial of a number ( n ) is product of all the integers from 1 to n )
  3. Find out highest common factor ( HCF ) or greatest common factor of two input numbers.

Functions All Built in Functions in Python


plus2net.com



Post your comments , suggestion , error , requirements etc here





Python Video Tutorials
Python SQLite Video Tutorials
Python MySQL Video Tutorials
Python Tkinter Video Tutorials
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
©2000-2021 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer