0% found this document useful (0 votes)
56 views2 pages

Python Factorial & Sum Program

The document presents a Python program that includes functions to calculate the factorial of a number and the sum of a list of numbers. It defines two functions: 'factorial' for computing the factorial recursively and 'sum_of_list' for summing elements in a list. The program tests these functions with a number and a list, outputting the results.

Uploaded by

singhmanasmay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
56 views2 pages

Python Factorial & Sum Program

The document presents a Python program that includes functions to calculate the factorial of a number and the sum of a list of numbers. It defines two functions: 'factorial' for computing the factorial recursively and 'sum_of_list' for summing elements in a list. The program tests these functions with a number and a list, outputting the results.

Uploaded by

singhmanasmay
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program 3

Q3. Write a menu driven Python Program to find Factorial and sum of list
of numbers using function.

Source Code:

# Function to calculate the factorial of a number


def factorial(n):
if n == 0 or n == 1:
return 1
else:
return n * factorial(n - 1)

# Function to calculate the sum of a list of numbers


def sum_of_list(numbers):
total = 0
for number in numbers:
total += number
return total

# Test the functions


number = 5
numbers_list = [1, 2, 3, 4, 5]

print(f"Factorial of {number} is {factorial(number)}")


print(f"Sum of the list {numbers_list} is {sum_of_list(numbers_list)}")

output:
Factorial of 5 is 120
Sum of the list [1, 2, 3, 4, 5] is 15

You might also like