Skip to main content

Featured

Introduction to Numpy Library in Python

Introduction to Numpy Library in Python NUMPY - Introduction Introduction     NUMPY stands for Numerical Python. Numpy is one of the libraries for the python programming language. It is used for high level mathematical calculations. It has the large collection of functions for working with the multi-dimensional arrays, matrices, linear algebra, Fourier transform, etc. Installation of Numpy 1. Open the command or terminal on your system. 2. Enter the following command below.      #installation of NUMPY using PIP      pip install numpy       (OR)       #installation of NUMPY using CONDA      conda install numpy 3. Now, NUMPY installed on your system. To verify that use the command below.      #check for version of NUMPY      numpy --version  Tip : Use Anaconda Navigator , it comes with built-in software of JUPYTER NOTEBOOKS and pre-installed packages like Nump...

Program for Hackerrank Average Function Code in Python

Python - Hackerrank Average Function Program

Python - Hackerrank Average Function Program
Python - Hackerrank Average Function Program


Source Code

Aim :

    To program a Hackerrank average function code in python.

Algorithm :

  • Get the required input from the user by using input statement for 'nums'(number).
  • Call the avg() function with passing parameter as 'nums'.
  • Write the required avg function definition.
  • The required information is successfully updated in the given file (junk.txt).

Program :

#!/bin/python3
import math
import os
import random
import re
import sys

def avg(*nums):
    return sum(nums)/len(nums)
if __name__ == '__main__':
    os.environ['OUTPUT_PATH'] = 'junk.txt'
    fptr = open(os.environ['OUTPUT_PATH'], 'w')
    
    nums = list(map(int, input("Enter the numbers : ").split()))
    res = avg(*nums)
    
    fptr.write('%.2f' % res + '\n')

    fptr.close()

Output :

Enter the numbers : 
10 10 10

Text That Appear On A Given File Are Below :

10.00

Terminal Code :

Python - Hackerrank Average Function Program
Python - Hackerrank Average Function Program


Terminal Output :

Python - Hackerrank Average Function Output
Python - Hackerrank Average Function Output


Result :

    The output was executed successfully and result was verified.


Personal Writings for Readers!!!

Story behind single family described in Pandemic Family Book.


Read more on...

Paperback - https://amzn.to/34NS6Sk

Amazon Kindle - https://amzn.to/3aKtIng

Kobo Writing - https://bit.ly/3iQysNy

Comments

Popular Posts