NAME :RAJ SHUBHAM MANOJ KUMAR
PRN NO: 04422001670
SEAT NO : 3188
SUB : 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)
2. Write a Python program to calculate the sum of all numbers from 1
to a given number.
CODE:
def calculate_sum(n):
total = 0
for i in range(1, n+1):
total += i
return total
number = int(input("Enter a number: "))
result = calculate_sum(number)
print("The sum of numbers from 1 to", number, "is:", result)