Write the following Python programs(list/tuple): 1. Traversing a list ...
#1. Python program to traverse a list
# entering a list from user
list1=eval(input ("Enter a list of numbers"))
l=len (list1)
# traversing the list
for i in range(0, l) :
print( "the elements in the list are", i)
#2. Python program to find the element by mentioning it index
# entering a list from user
list1=eval(input(" enter a list of numbers:"))
l=len (list1)
# entering the element from the user for which index is mentioned
for i in range (0, l) :
index=int(input (" enter the index :"))
if index=list1(index[i])
print(" the element at index", index, "is:", [i])
else:
print(" element not found")
#3.# Python program to find the index by mentioning element
it is similar to the question 2 above just use the element function instead of index function
4. the procedure is same for entering the list from user then calculate the length by using len () function then find the sum of the numbers in the list by using sum() function
then calculate the median as m=sum_numbers/l
and I show the median by printing it
5. use Max and min function to find the maximum and minimum number in the list of number
Write the following Python programs(list/tuple): 1. Traversing a list ...
1. Traversing a list:
```python
my_list = [1, 2, 3, 4, 5]
for element in my_list:
print(element)
```
2. Finding the element by mentioning its index:
```python
my_list = [1, 2, 3, 4, 5]
index = 2
element = my_list[index]
print(element)
```
3. Finding the index of an element by mentioning it:
```python
my_list = [1, 2, 3, 4, 5]
element = 3
index = my_list.index(element)
print(index)
```
4. Finding the mean:
```python
my_list = [1, 2, 3, 4, 5]
mean = sum(my_list) / len(my_list)
print(mean)
```
To make sure you are not studying endlessly, EduRev has designed Class 10 study material, with Structured Courses, Videos, & Test Series. Plus get personalized analysis, doubt solving and improvement plans to achieve a great score in Class 10.