Python Forum
while loops - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: while loops (/thread-38789.html)



while loops - CJM125 - Nov-24-2022

I'm completely new to Python and coding in general. I've been asked to 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. Any help would be appreciated.


RE: while loops - Larz60+ - Nov-24-2022

Please make an effort at writing the code.
Then post your code, working or not, with any error messages, and your question.

Please read: Homework and No Effort Questions


RE: while loops - BliepMonster - Nov-25-2022

(Nov-24-2022, 10:08 PM)CJM125 Wrote: I'm completely new to Python and coding in general. I've been asked to 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. Any help would be appreciated.

You could use a while loop and a for loop.


RE: while loops - rob101 - Nov-25-2022

(Nov-24-2022, 10:08 PM)CJM125 Wrote: I'm completely new to Python and coding in general. I've been asked to 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. Any help would be appreciated.

One approach would be to write some pseudocode:

# get the user input
# is the input -1
# no:
    # store the input and loop back to get another input
# yes:
   # stop asking for input and process the list of inputs
So, you need to know how to get some user input and check the requirement; that's your first step.

Have you been asked to do this, with no tuition, or have you been given some tuition?

Have a look at this site for, not only the fundamentals, but also more advanced topics.


RE: while loops - jefsummers - Nov-26-2022

And in the while loop, the walrus operator is ideal.