Project Level 1: Beginner
This project is designed for beginner learners who are still learning and practicing Python fundamentals.
Project Skills Needed
This project covers the following concepts. Click any link to learn more about them if you're unfamiliar.
functions | lists | print() function | sum() function
Project Description
Build a program that has a function that takes a list of numbers and calculates their sum, providing the total sum as output to the user.
How the Project Works
The program starts by defining a function that takes a list of numbers as input.
The function iterates through the list, adding each number to a running total.
After iterating through the list, the total sum is returned.
The user then prints the result using a
print()
function that calls the sum function and converts the output to a string.
Prerequisites
Required Libraries: No libraries are required.
Required Files: No files are required.
IDE: You can use any IDE on your computer to code the project.
Danger Zone
Feel free to use the hints below for help:
Once you code the project, compare it with our solution below:
print("The sum of the numbers is: " + str(calculate_sum(numbers_list)))
def sum_list(n):
total = 0
for i in n:
total += i
return total
n = list(map(int, input("Enter numbers separated by commas: ").split(",")))
print("The sum is", str(sum_list(n)))