a) Write a Python program, which display the sum of even values and sum of odd values of a given list separately. 3 Example: if the list contains values: 22 21 25 20 Then the functions should display the output as: Sum or even values = 42 (ie 20*22) Sum of odd values - 99 (ie 25+21+53) b) Write a python program to display the lowercase letters of a string in uppercase and uppercase letters in lowercase. 3 Example String Good Morning Output="goog MORNING,
Answers
Answered by
0
Answer:
# Python program to find out
# Sum of elements at even and
# odd index positions separately
# Function to calculate Sum
def EvenOddSum(a, n):
even = 0
odd = 0
for i in range(n):
# Loop to find evem, odd Sum
if i % 2 == 0:
even += a[i]
else:
odd += a[i]
print "Even index positions sum ", even
print "nOdd index positions sum ", odd
# Driver Function
arr = [1, 2, 3, 4, 5, 6]
n = len(arr)
EvenOddSum(arr, n)
Explanation:
hope it helps
Similar questions