title: How to make a part of a code go in loop without duplicate the code in Python
body: <p>I'm using pyttsx3 to make a talking bot . and it work</p>
  <pre><code>import pyttsx3
  f = pyttsx3.init()
  
  a = input(&quot;type something: &quot;)
  
  if a == &quot;hello&quot;:
      print(f.say(&quot;Hi How are you&quot;))
  
  f.runAndWait()
  </code></pre>
  <p>but if I want the code to repeat the operation when ever its end I mean if I typed something and got the respond I will get another &quot;type something&quot; input without duplicate the code like this</p>
  <pre><code>import pyttsx3
  f = pyttsx3.init()
  
  a = input(&quot;type something: &quot;)
  
  if a == &quot;hello&quot;:
      print(f.say(&quot;Hi How are you&quot;))
  f.runAndWait()
  
  b = input(&quot;type something: &quot;)
  
  if b == &quot;hi&quot;:
      print(f.say(&quot;Hi&quot;))
  f.runAndWait()
  c = input(&quot;type something: &quot;)
  
  if c == &quot;hey&quot;:
      print(f.say(&quot;hi hows going&quot;))
  
  f.runAndWait()
  </code></pre>
  <p>i tried making a loop but didn't work</p>
  <pre><code>import pyttsx3
  f = pyttsx3.init()
  
  a = input(&quot;type something: &quot;)
  
  if a == &quot;hello&quot;:
      print(f.say(&quot;Hi How are you&quot;))
  
  for a in f:
      print(a)
  
  f.runAndWait()
  </code></pre>
  <p>So its going to ask me the a input again and  again with no need to duplicate the code</p>