Write a code segment that uses a while loop, the input function and any other necessary code to efficiently accumulate the total of the numbers inputted by the user that are between or including 5 and 9. Trace the code assuming the user inputs the values 6, 9, 3, 5 and -1 where -1 is a sentinel value that causes the loop to terminate.

Relax

Respuesta :

In python:

total = 0

while True:

    number = int(input("Enter a number: "))

    if 5 <= number <= 9:

        total += number

   elif number == -1:

       break

print(total)