+ 1

what is wrong with this code?

s=0 o=0 n=int(input()) for i in range (1, n+1): k=int(input()) for j in range(1, k+1): a=int(input()) while o<=k: o+=1 s+=a break m=s/k print(m) Input 2 7 1 5 1 5 4 4 1 10 3 5 3 3 4 1 3 1 3 1 Output 3.0 2.7

9th Apr 2022, 8:02 AM
Angelina
4 Answers
+ 2
Angelina , without having a task description of what the code should achieve, we only can guess. thanks!
9th Apr 2022, 9:21 AM
Lothar
Lothar - avatar
+ 2
First of all, what are you doing here. If you're up against a problem that needs to relly on an array of numbers just use lists and tuples. If your program is going to find a result like average or mean, then use a function iterating over an array of numbers. The problem lies also in the logic of code ( why would you just add a `break` in `while` while you could solve it without it ?), and at inputs .... You are taking a lot of inputs, why don't you try to make it more friendly like: numbers = tuple(map(int,input('Enter numbers separated by spaces: ').split())) And,... just try to not overuse loops.
9th Apr 2022, 11:57 AM
Ervis Meta
Ervis Meta - avatar
+ 2
Ervis Meta - SoloHelper , have you tried to run your code sample?
9th Apr 2022, 7:05 PM
Lothar
Lothar - avatar
+ 2
Sorry I fixed it 😅
9th Apr 2022, 7:10 PM
Ervis Meta
Ervis Meta - avatar