Reputation: 21
Given a sorted list of integers, output the middle integer. Assume the number of integers is always odd
Input: 2 3 4 8 11
Output: 4
This is what I have so far
inputs=[]
num_inputs=int(input())
if(num_inputs>9):
print("Too many inputs")
else:
print(num_inputs)
for i in range(num_inputs):
inputs.append(input())
print(inputs)
middle_position=int(num_inputs/2)
print(inputs[middle_position])
Upvotes: 0
Views: 1409
Reputation: 191701
Your input is only one line of data.
To read that into a list, you would use
inputs = list(map(int, input().split()))
Or just inputs = input.split()
since you don't need ints
Then you would just need to check len(inputs) > 9
and get inputs[len(inputs) // 2]
. No loops
Upvotes: 1