'Calculating Average number and Minimum number out of 10 integers [duplicate]
I need to write a program where you can only input 10 numbers, and from those 10 numbers it then will print the minimum number out of the 10 inputted numbers and then print average of all the numbers.
Instructions: Write a program that reads 10 integers and displays its minimum and average.
What I have so far:
c=1
min=int(input("a number>1: "))
while c<10:
v=int(input("a number>2: "))
print (min)
print (v)
if min>v:
min=v
c += 1
d = sum(int(min+v)
print (d)
print ("Minimum number: " + str(min))
Or this:
a = 0
b = int(input("a number>1: "))
while a < 10:
c = int(input("a number>1: "))
d = int(input("a number>1: "))
e = int(input("a number>1: "))
f = int(input("a number>1: "))
g = int(input("a number>1: "))
h = int(input("a number>1: "))
i = int(input("a number>1: "))
j = int(input("a number>1: "))
k = int(input("a number>1: "))
a += 1
if (b>c and b<d and b<e and b<f and b<g and b<h and b<i and b<j and b<k):
print ("Minimum is" + str (b))
# c =
# a += 1
#print(min)
Solution 1:[1]
You can create two variables; one that will hold the sum of the numbers (in which at the end, you just divide that number by 10) and another that will hold the minimum value.
We will set the min and sum to the first number then create a loop to obtain the next 9 numbers using the function range(start, end) which would count from start to end-1 (whatever value you pass as the second parameter, will not be included in the loop).
Then in the loop, you can allow the user to enter the number in which you will: add it to the sum variable and set it has the minimum if it is less than the current value of the min variable.
min = int(input('Enter a number > 1: '))
sum = min
for i in range(0, 9):
number = int(input('Enter a number > 1: '))
sum += number
if number < min:
min = number
average = sum / 10
print('Minimum:', str(min))
print('Average:', str(average))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
