0

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]) 
0

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.