## butterflyTee Light Poster

# sum.py
# tpm
# A program that accepts an indeterminate (any number) of integers entered by
# the user, calculates and their sum, using loop

``````from math import *

def calc_sum():
n = input("Enter any number: ")
sum = 0.0
for i in range(n):
x = input("Enter a number >> ")
sum = sum + x
print "\nThe sum of the numbers is", sum / n

main()``````

## ghostdog74 57

# sum.py
# tpm
# A program that accepts an indeterminate (any number) of integers entered by
# the user, calculates and their sum, using loop

``````from math import *

def calc_sum():
n = input("Enter any number: ")
sum = 0.0
for i in range(n):
x = input("Enter a number >> ")
sum = sum + x
print "\nThe sum of the numbers is", sum / n

main()``````

why do you need to /n when you only want to calc the sum of these numbers?
and where is your main() ?? it should be calc_sum() right?

## bumsfeld 413

Use the while loop for indeterminate number of entries, for loop for fixed number. If you need to use main(), define main to call your calc_sum function. Let the user know how to stop the loop.

``````# while loop is used to sum an indeterminate number of integers entered, until you enter a zero

def calc_sum():
sum = 0
x = input("Enter a number (0 to stop) >> ")
while x != 0:
sum = sum + x
x = input("Enter a number (0 to stop) >> ")
print "\nThe sum of the numbers is", sum

def main():
calc_sum()

main()``````