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(): num = int(input('Enter an integer: ')) sum = 0 while num != 0: sum = sum + num num = int(input('Enter an integer: ')) return sum add_all()

Questions about programming?Chat with your personal AI assistant