Can someone please help me with this question, still new at while loops

Posted May 2, 2019 1.1k views

● Create a new file called 
● Write a program that always asks the user to enter a number.    ● When the user enters the negative number -1, the program should stop  requesting the user to enter a number, 
● The program must then calculate the average of the numbers entered excluding  the -1. 
● Make use of the while loop repetition structure to implement the program. 
● Compile, save and run your file. 

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer


It is unusual to have such kind of questions here but I will give you an answer, write this in your new file and execute it with python3

sum = 0
i = 0
while True:
        n = int(input("Input a number "))
        if n == -1:
        sum += n
        i += 1

print("Average is {}".format(sum/i))

To learn about python I highly recommend this book about Python programming It is a collection of all python related tutorials in our community.

Hope this helps