In: Computer Science
Given a list x = [2,3,5,6,7,8,9], write a python program that find those numbers which are divisible by 3. Arrange these numbers in a list called “result”.
Hint: similar to page 9 in the slides.
Dear Student ,
As per the requirement submitted above , kindly find the below solution.
Here a new python program with name "main.py" is created, which contains following code.
main.py:
#python list
x=[2,3,5,6,7,8,9]
result=[] #empty list
#loop through each element in the list
#and find the numbers which are divisible by 3
for element in x:
#checking if number is divisible by 3
if element%3==0:
#if number is divisible by 3,
#then add number in the list result
result.append(element) #add element end of the list
#print result list
print(result)
======================================================
Output : Compile and Run main.py to get the screen as shown below
Screen 1 :main.py
NOTE : PLEASE FEEL FREE TO PROVIDE FEEDBACK ABOUT THE SOLUTION.