Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while loop stumbling block
#4
(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: "))

    
Reply


Messages In This Thread
while loop stumbling block - by YoungGrassHopper - Sep-09-2019, 06:27 PM
RE: while loop stumbling block - by ichabod801 - Sep-09-2019, 06:35 PM
RE: while loop stumbling block - by YoungGrassHopper - Sep-09-2019, 07:55 PM
RE: while loop stumbling block - by ichabod801 - Sep-09-2019, 08:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Stop/continue While loop block Moris526 68 40,133 Mar-28-2021, 09:21 PM
Last Post: Larz60+
  for loop stumbling block YoungGrassHopper 8 6,831 Sep-11-2019, 03:34 PM
Last Post: YoungGrassHopper

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020