Shubham Raj Python Practical
Shubham Raj Python Practical
1. Write a Python program find the sum of all numbers stored in list.
CODE:
def sum_of_numbers(numbers):
total = 0
for num in numbers:
total += num
return total
my_list = [1, 2, 3, 4, 5]
result = sum_of_numbers(my_list)
print("The sum of the numbers in the list is:", result)
CODE:
def calculate_sum(n):
total = 0
for i in range(1, n+1):
total += i
return total