Sep-09-2019, 07:55 PM
(This post was last modified: Sep-09-2019, 08:04 PM by YoungGrassHopper.)
(Sep-09-2019, 06:35 PM)ichabod801 Wrote: You need two variables: one for the name most recently entered, and one for the list of names that have been entered. Call them next_name and names. The input statement goes to next_name. If that's 'stop', you break out of the loop and print names. Otherwise, you append next_name to names.
Ok,
I gave it a try, but what I am getting is only the first name printed and not more than one name.
The user will obviously enter 1 name, press enter, get requested to enter another name... until he enters "Stop" I only seem to get the first name entered..
I literally started coding past Thursday so please don't get angry with me.
It would be best to explain as if I am a 4 year old. And I apologise if I am proving to be a waste of your precious time.
next_name = input("Enter student name: ") names = 0 while names != "Stop": names = input("Enter student name: ") if names == "Stop": print(next_name)
Another while loop stumbling block I have is this:
The program needs to ask the user to repeatedly enter a number and stop + exit the loop once the user enters:
"-1"
The program must then calculate the average of the numbers entered excluding the -1.
The first part I think I have correct, but I do not know how to calculate the average of all the inputted numbers prior to " -1 "
Here is what I have so far:
num = int(input("Please enter a number: ")) while num != -1: num = int(input("Please enter a number: "))