We have a function called avg that takes in a variable number of integer inputs. We have to complete it such that it returns the average of all the input integers.

```
def avg(*nums):
pass
```

This is the function that we need to complete.

The *args is a special syntax in python used to define a variable number of inputs. Having a * before the name of the argument means it is a variable input. All the inputs are available in this argument as a list

avg(1,2,3,4) means that the nums will be [1,2,3,4]. we can use this to calculate the average.

## Code for Python Average Function Hackerrank Solution

```
def avg(*nums):
sum = 0
length = 0
for n in nums:
sum += n
length += 1
return sum/length
print(avg(1,2,3,4,5))
```

### Output:

3.0

## Single Line Code

We can also write the code in a single line using python

```
def avg(*nums):
return sum(nums)/len(nums)
print(avg(1,2,3,4,5))
```

### Output:

3.0

**Also Read:**

- Item Price Generator Hackerrank Solution
- Insertion Sort Part 2 Hackerrank Solution in C
- Extra Long Factorials Hackerrank Solution
- Java Datatypes Hackerrank Solution
- Smart Number Hackerrank Solution
- Python Average Function Hackerrank Solution
- Company Logo Hackerrank Solution
- Matrix Summation Hackerrank Solution
- A company is repainting its office – HackerRank Solution
- Maximum Product Subarray in O(N) Time – Leetcode Solution
- Minimum number of transformation steps required to make all elements of an array equal
- NxNxN Matrix in Python 3
- Boruvka’s Algorithm in Python
- Roti Prata SPOJ Problem Solution – Complete Solution Approach with C++ and Java Code
- Lee Algorithm in Python | Solution to Maze Routing Problem in Python
- Vending Machine with Python Code
- Top 20 Array Coding Questions for Online Assessment
- Heap Sort Algorithm in Python
- Heap Sort Algorithm|Heap Data Structure
- Insertion Sort Algorithm in Data Structures using Python
- Quick Sort algorithm in data structures and algorithms using Python
- Selection Sort Algorithm In Data Structures and Algorithms using Python
- Searching Algorithms: Linear Search Algorithm
- Bubble Sort Algorithm In Data Structures & Algorithms using Python
- Merge Sort Algorithm in Python
- Binary Search in python
- Linear Search Python
- Sorting Algorithms and Searching Algorithms in Python
- Binary Search In Python
- Adding three matrices