Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
while loop stumbling block
#1
Hey guys, I am very new to coding so please bare with me. I am busy with a python bootcamp trying to learn as much as quick as I can. I am currently busy with loops, while loops in particular. What I need to make the program do:

ask a user via input command to enter all student names and once he enters "Stop" the loop of asking him/her to enter the next name must stop. I think I have that part sorted. The next part is my struggle:

After the user enters: "Stop" :

The names of the students needs to be printed out, without the "Stop" being printed as that is obviously not a students name.


My attempt at coding the above looks like this:

names = input("Enter student name: ")
while names != "Stop":
    names = input("Enter student name: ")
    if names == "Stop":
        print(names)
So the result I am getting is the phrase "Stop" being printed instead of the student names entered prior to "Stop"

I would deeply appreciate some assistance.
Thanks in advance.

The YoungGrassHopper
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 ichabod801 - Sep-09-2019, 08:25 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Stop/continue While loop block Moris526 68 26,857 Mar-28-2021, 09:21 PM
Last Post: Larz60+
  for loop stumbling block YoungGrassHopper 8 4,765 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