0
import pyttsx3

robot = pyttsx3.init()

while True:
 robot.say(input('Write something that you need me to say:\n'))
 robot.runAndWait()

 n = (input('if you need to quit type : quit , if you need to write again 
 press any button\n'))

 if n == 'Quit' or 'quit' or 'QUIT':
  break
 else:
  continue

I want to ask the user if he want to quit or write again but when I run my code it breaks the loop any way.

martineau
  • 119,623
  • 25
  • 170
  • 301
Eyad
  • 13
  • 2

1 Answers1

0

Not sure what those robot lines are doing so I commented them out since they are not related to the bug I found in your code. I got this to work by correcting your use of or statements and using case insensitive check instead:

import pyttsx3

robot = pyttsx3.init()

while True:
  # robot.say(input('Write something that you need me to say:\n'))
  # robot.runAndWait()

  n = (input('if you need to quit type : quit , if you need to write again press any button\n'))

  if n.lower() == 'quit':
    print("quitting...\n")
    break
  else:
    print("continuing...\n")
    continue

Explanation:

You wrote if n == 'Quit' or 'quit' or 'QUIT' - which means "If n equals 'Quit' or if 'quit' is truthy (it is) or 'QUIT' is truthy (it is), proceed this way: break" hence the termination you saw. If you wanted to use or correctly, the expression would need to read:

if n == 'Quit' or n == 'quit' or n == 'QUIT
JacobIRR
  • 8,545
  • 8
  • 39
  • 68