control structure for for loop
# Program to find the sum of all numbers stored in a list
# List of numbers
numbers = [6, 5, 3]
# variable to store the sum
sum = 0
# iterate over the list
for val in numbers:
sum = sum+val
# Output: The sum is 48
print("The sum is", sum)
# List of numbers
numbers = [6, 5, 3]
# variable to store the sum
sum = 0
# iterate over the list
for val in numbers:
sum = sum+val
# Output: The sum is 48
print("The sum is", sum)
Comments
Post a Comment