Monday, 21 February 2022

Write a program to sum a series of numbers entered by the user.

 Write a program to sum a series of numbers entered by the user. The program should first prompt the user for how many numbers are to be summed. The program should then prompt the user for each of the numbers in turn and print out a total sum after all the numbers have been entered. Hint: Use an input statement in the body of the loop.

CODE

# sumnn.py 

def main() :

    n = int (input ("How many numbers are to be summed: ") ) 

    sum=0

    for i in range(n) :

        n = int (input ("Please enter number  : ") ) 

        sum=sum+n

    print ("Total Sum  :",sum) 

main()

SCREENSHOT




No comments:

Post a Comment