-2
Description: Make a program that displays the average between the highest and lowest value of an integer vector with twenty user-given elements and, at the end, displays only those elements that are greater than average.
Input format: Twenty whole numbers, one per line.
Output format: In the first line, the phrase "media: #" (without quotation marks, in lower case, without accentuation and with # replaced by the average of the numbers read and with two decimal places); in the following lines, the values given in the input are greater than the average, in the same sequence as read and one per line
Code that is being used:
arr = []
soma = 0
for p in range(20):
x= int(input())
arr.append(x)
soma = soma + x
media = soma // len(arr)
if media < 0:
print('media: 0.00')
else:
print('media: %.2f' % media)
for b in range(20):
if arr[b] > media:
if arr[b] != 0:
print(arr[b])
When I submit, the first two test cases of the program, it works, however, the last two test cases, it does not work, and the program does not hint what is occurring, I think there is some wrong part, or some gambiarra that I have done...
Entrada:
5
1
7
-6
-9
-6
0
-2
10
-6
-8
3
-4
-9
9
8
-7
3
-7
-10
Saída
media: 0.00
5
1
7
10
3
9
8
3
And what you need help with?
– Woss
our code is not working!
– Baria
arr = [] soma= 0 for _ in range(20): x = int(input()) arr.append(x) soma = sum + x media = sum // Len(arr) if media <= 0: print("media: 0.00") Else: print("media: %.2f" media) for b in range(20): if arr[b] > media: if arr[b] != 0: print(arr[b])
– Baria
Edit the question, add the code and explain what has been done and what is currently happening.
– Woss
editions are made!
– Baria
1) Ask for the average between the highest and lowest value of the list, not the average of all; 2) Why is 0 displayed when the calculated mean is negative? Not in the statement specifying this; 3) Why use
//
to calculate the average? It shouldn’t be a real number? 4) Why, when displaying above-average values, is it checked if the value is different from 0? If it is zero it should not be displayed even if it may be above average? It also does not say in the statement on this.– Woss
I will edit the entries and outputs that the program also
– Baria
What about the four questions in the previous comment?
– Woss