-4

Guys python is just straight-up wrong. Here is my code:

#Repeat until loop
count = 0
while (count < 9):
  print("What is your name?")
#If creator code 
 x = input("Type Stop program or enter your name ")
  if x == "QiwiCode":
      print("")
      print("Good morning creator")
      print("")
#Quit code 
 elif x == "Stop program" or "stop program" or "stop Program" or "Stop Program":
      print("Quitting.")
      time.sleep(1)
      print("Quitting..")
      time.sleep(1)
      print("Quitting...")
      time.sleep(1)
      print("Goodbye")
      count = 10
#Name if not creater or quit code
elif x != "Stop program" or "stop program" or "stop Program" or "Stop Program" or "QiwiCode":
      print("")
      printdHello",x,)
      print("")

I put in a random name (tom) and it just ran the quit function! Can someone help?

QiwiCode
  • 15
  • 1
  • 6
  • 2
    `elif x == "Stop program" or "stop program"` That is not the right way to check for multiple values. See this question https://stackoverflow.com/q/15112125/494134 – John Gordon Feb 06 '21 at 16:56
  • 2
    tip - If you ever find yourself saying that "x is wrong" where x is an established, 30 yrs old, widely used language - it is more likely that **you** did something wrong – DeepSpace Feb 06 '21 at 17:02
  • 1
    @DeepSpace yes, especially if it is some basic facet of the language, like an if-else statement – juanpa.arrivillaga Feb 06 '21 at 17:16
  • Anyway, python's syntax is often pretty close to natural language English, but it's important to remember it isn't a natural language, it's a programming language. The "or" doesn't distribute like that, so in english, "the ball is red or green or blue" means the same as "the ball is red or the ball is green or the ball is blue" but python doesn't work like that, – juanpa.arrivillaga Feb 06 '21 at 17:23

1 Answers1

1

Your elif's can be improved a little bit.

change : elif x == "Stop program" or "stop program" or "stop Program" or "Stop Program":

to : elif x == "Stop program" or x == "stop program" or x == "stop Program"...

Noticed the x I added? Try to add it to the other elif and it might work.

EDIT: This will solve your problem and will work (Probably). But as John Gordon pointed out. You could force x to lowercase, then doing something like

elif x.lower() == "stop program":

Then it doesn't matter if it's "Stop Program", "stoP Program" or "sToP PRogRaM", it will work for all of them.

Sami
  • 117
  • 1
  • 3