Python Function With No Parameter, No Return

Advertisements
Advertisements

In the last article, we have seen how a user-defined function is created. The user-defined function has two parts – the function definition and the function call.The function definition may or may not have parameters and it may or may not return a value.

In this article, you will see an example of python function with no parameters, and no return.

Program to Compute Factorial of a Number

This program is a simple program that computes factorial of a given input number.

## Program To Compute Factorial of a Number
## Function Definition
def factorial_number():
    
     factorial = 1
     fact_number = int(input("Enter a Number to Get its Factorial: "))
     for i in range(1, fact_number + 1):
        factorial = factorial * i
     print("The factorial is" , factorial)
## Function Call
factorial_number()

The above program does not take any parameters and does not return anything. The output of the program is given below.

========= RESTART: C:/Python_projects/Functions/Factorial.py =============
Enter a Number to Get its Factorial: 5
The factorial is 120
>>> 

In the next article, we will discuss about function with parameter with return.

Advertisements

Bestseller

Python Programming: Using Problem Solving Approach

Python Programming is designed as a textbook to fulfil the requirements of the first-level course in Python programming. It is suited for undergraduate degree students of computer science engineering, information technology as well as computer applications. This book will enable students to apply the Python programming concepts in solving real-world problems. The book begins with an introduction to computers, problem solving approaches, programming languages, object oriented programming and Python programming. Separate chapters dealing with the important constructs of Python language such as control statements, functions, strings, files, data structures, classes and objects, inheritance, operator overloading and exceptions are provided in the book. Each chapter ends with objective-type questions, review questions, programming and debugging exercises to facilitate revision and practice of concepts learnt.


Advertisements
Advertisements
Advertisements