generate functionThu, 16 Feb 2023

The user enters integers one per line, the sequence ends with the number 0. Anything after 0 is not part of the sequence. Write a program that prints the sum of all terms in a given sequence.

def add_all(): sum = 0 while True: num = input() if(num == "0"): break sum = sum + int(num) return sum add_all()

Questions about programming?Chat with your personal AI assistant