Write a program that prints out all the elements of the list that are less than 5
Answers
Answer:
""" 1.) Understand the problem
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
and write a program that prints out all the elements of the list that are less than 5.
2.) Plan a solution
Algorithm:
- Create new empty list
- For loop to iterate over each element
- If element < 5:
- Append the element into new list
- Print the new list
3.) Carry out the plan
"""
a = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
new_list = []
for item in a:
if item < 5:
new_list.append(item)
print(new_list)
""" 4.) Examine your results for accuracy:
b = [1,1,2,3]
"""
Following are the program in python programming language
Output:
1
2
Explanation:
list1 = [12, 1, 2, 32, 5, 8, 123, 221, 324, 525, 892] #list
for ar in list1: #iterating the loop
if ar < 5: #check the condition
print(ar) #print
Following are the description of program
- Declared a list 'list1" that contains the elements .
- iterating the for loop .
- Checking the condition list elements are less then 5.
- Print the list.
Learn More :
- https://brainly.in/question/14865671