-1

I've been trying to make a line management program, but something isn't working properly and only half of it works.

I've tried to move things around and change if statements to else statements. but still only half if it works. what's meant to happen is, the user type in a word, if that word = Next, it removes the first person in that line. if the user types any other word but Next, it adds it to the end of the list.

Example below:

# This is just a line manager :D

print("")

Line = \["Bob" , "Steve" , "Michael"\]
print(Line)

print("")

#infinit loop

I = 0

while I < 1:

   print("Type the name of the person you want to add to the queue, or if you wanna remove the first person in the line, type 'Next'")

   print("")

   New = str(input())

   if New != "Next" or "next":

      Line.append(New)
      print(Line)

      continue

   if New =="Next":

      Line.remove(Line\[0\])

      print(Line)
Caridorc
  • 6,222
  • 2
  • 31
  • 46
CatXx
  • 11
  • 3
  • Careful about if statements: `New != "Next" or "next"` -> `New != "Next" or New != "next"`. – Caridorc Feb 13 '23 at 12:35
  • Please provide a descriptive title for your question. – S.B Feb 13 '23 at 12:35
  • Welcome to Stack Overflow. Please take the [tour] and read [ask] - you have already done two things wrong by the title (it seems someone else edited the title for you): failing to describe an actual problem, and talking about yourself rather than the code. Note well that this is **not a discussion forum**. – Karl Knechtel Feb 13 '23 at 12:37

1 Answers1

0

The error is on this line:

if New != "Next" or "next":

The second half, or "next", checks the truthiness of the string "next", which is true since it's a non-empty string. Also, it should check if the answer is neither, not either or. Instead, do it like this:

if New != "Next" and New != "next":

or even tidier:

if New not in ["Next", "next"]:

But in this case (and any taking user input), use this:

if New.lower() != "next":

which turns the user input to lowercase :)

B Remmelzwaal
  • 1,581
  • 2
  • 4
  • 11
  • 1
    The logic with `!=` should use `and`, rather than `or`, due to de Morgan's law. (I added a separate duplicate link to cover that material.) Anyway, please read [answer] and do not attempt to answer questions that are common duplicates. – Karl Knechtel Feb 13 '23 at 12:40