Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

How Do I get the middle term of a list with unknown amount of items

–1 vote
asked Jun 11, 2019 by Patryck Yee (110 points)
I need to be able to print the middle item in a list using some type of list slicing. The only thing is that the user decides how many items are in the list.

2 Answers

+1 vote
answered Jun 12, 2019 by anonymous

list = [1,2,3,4,5,6,7]

print("length of list is = ",len(list))

print("middle element of the list =",list[int((len(list))/2)])

0 votes
answered Jun 12, 2019 by ayush
use len() function

import the length of the list in a variable

divide it by 2

print that number of element of the list as that is the middle element of the list
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...