Example user input- list size and list elements are
Python Program Assignment Answers
Question:
Write a python program to find the sum of elements which are stored at odd indexed and divisible by 3 in a list of integers. Create the list by asking the user the size and elements of the list. Example: (i) (User Input-> List size =6 and List elements are= 10, 12, 5, 9, 19, 31, 42 Then the output is 21)
Python Program Answer and Explanation
if lst[i] % 3 == 0: # Check if the element at the odd index is divisible by 3
result += lst[i] # Add the element to the result
# Input list elements from the user
elements = []
result = sum_odd_divisible_by_three(elements)
print("Sum of elements at odd indices and divisible by 3:", result)