To accept N numbers from user. Compute and display maximum in list, minimum in list,sum and average of numbers.

Bit Byte
2 min readJun 22, 2023

--

  • **whole code is below***

Title: To accept N numbers from user. Compute and display maximum in list, minimum in list,
sum and average of numbers.

Introduction:
In this blog post, we will explore a simple Python script that allows users to input a series of numbers and perform basic calculations such as finding the maximum and minimum values, calculating the sum, and determining the average. This script serves as a handy tool for beginners who want to familiarize themselves with Python’s syntax and basic arithmetic operations.

Code Explanation:
Let’s dive into the code and understand how it works:

  • 1. User Input:
    The script starts by prompting the user to enter the total number of values they want to input. This helps in determining the range for subsequent number inputs.
  • 2. Number Input:
    Once the total number is provided, the script enters a loop that iterates `N` times. Within this loop, users can input individual numbers, which are stored in a list called `Num_list`.
  • 3. Maximum and Minimum Calculation:
    After the user has entered all the numbers, the script calculates the maximum and minimum values using the `max()` and `min()` functions, respectively. These functions efficiently identify the highest and lowest values within the `Num_list`.
  • 4. Sum Calculation:
    The script initializes a variable called `sum` to zero and enters another loop that iterates through the numbers in `Num_list`. With each iteration, the corresponding number is added to the `sum` variable. By the end of the loop, the sum of all the numbers is obtained.
  • 5. Average Calculation:
    Using the sum obtained in the previous step, the script calculates the average by dividing the sum by the total number of values. The result is stored in the variable `avg`.
  • 6. Results Display:
    Finally, the script utilizes `print()` statements to display the calculated results. It shows the maximum and minimum values, the sum of all the numbers, and the average value.

Code:

#enter total numbers
N=int(input(“enter total number: “))

#enter total numbers from 0 to N-1
for i in range(0,N):
num=int(input(“enter number: “))
Num_list.append(num)
#calculating maximum and minimum number
maximum=max(Num_list)
minimum=min(Num_list)

#calculating sum
sum=0
for i in range(0,N):
sum+=Num_list[i]

#calculating average
avg=sum/N

#printing results
print(“maximum number:”,maximum)
print(“minimum number:”,minimum)
print(“sum:”,sum)
print(“average:”,avg)

Conclusion:
In this blog post, we examined a simple Python script that enables users to perform basic calculations on a series of numbers. By following the step-by-step explanation of the code, readers can gain a better understanding of how to handle user input, manipulate lists, and utilize built-in functions for maximum, minimum, sum, and average calculations. This script serves as a starting point for beginners to explore Python’s syntax and gain confidence in handling simple arithmetic operations.

--

--

Bit Byte

we aim to bridge the gap between theory and practice, acknowledging the importance of hands-on experience in the tech industry..