title: Unexpected prints
body: <p>I am trying to make a little program which can register a word in Spanish (I am from Spain), the meaning in English and other thing which I have called &quot;Complicado&quot;. &quot;Complicado&quot; is not relevant at this point of the program. I am really confused with the behavior of the code. I don't know why \n is not working how I thought it works. Furthermore some lines are getting printed before I would like.</p>
  <p>The problem is in the if eleccion == 2.
  For instance, when eleccion is equal to 2 I expected the prints would be:</p>
  <pre><code>Empieza el test...
  Pregunta número 1
  Empieza el test...Indica el equivalente castellano de la palabra: Hello (Or the other possibility)
  </code></pre>
  <p>But this is a capture of my console:<br />
  <a href="https://i.stack.imgur.com/vDOAB.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/vDOAB.png" alt="Capture of my console" /></a></p>
  <p>I attached below the code.
  I appreciate all the help possible</p>
  <pre><code>import json
  import random
  
  eleccion = input(&quot;¿Añadir palabras?. (1)\n¿Test?.            (2)\nLista.             (3)\n&quot;)
  eleccion = int(eleccion)
  if eleccion == 1:
      esp = str(input(&quot;¿Español?: \n&quot;))
  
      ing = str(input(&quot;¿Inglés?: \n&quot;))
      
      f = open('ingles.json')
    
      data = json.load(f)
        
      data.append({&quot;Esp&quot;:esp, &quot;Ing&quot;:ing, &quot;Complicado&quot;: 0})
        
      with open(&quot;ingles.json&quot;, &quot;w&quot;, encoding=&quot;utf-8&quot;, newline=&quot;&quot;) as file:
          json.dump(data, file, indent=2)
      f.close()
  
  elif eleccion == 2:
      #Test
      aciertos = 0
      preguntas = 0
      print(&quot;Empieza el test...\n&quot;)
      a = 1
      f = open('ingles.json')
      data = json.load(f)
      while a != 0:
          print(&quot;Pregunta número: &quot;+str(preguntas+1) +&quot;\n&quot;)
          rand = random.randint(0,len(data)-1)
          rand2 = random.choice([2, 3])
          h = data[rand]
          if rand2 == 2: #Preguntas el inglés dando el español
              res = input(&quot;Indica el equivalente inglés de la palabra: &quot; + h[&quot;Esp&quot;]+ &quot; &quot;)
              print(&quot;\n&quot;)
              if res.upper() == h[&quot;Ing&quot;].upper():
                  aciertos += 1
                  print(&quot;\nCorrecto \n&quot;)
              else:
                  print(&quot;\nError \n&quot;)
          elif rand2 == 3:
              res = input(&quot;Indica el equivalente castellano de la palabra: &quot; + h[&quot;Ing&quot;] + &quot; &quot;)
              print(&quot;\n&quot;)
              if res.upper() == h[&quot;Esp&quot;].upper():
                  aciertos += 1
                  print(&quot;\nCorrecto \n&quot;)
              else:
                  print(&quot;\nError \n&quot;)
          preguntas += 1
          a = int(input(&quot;Para otra pregunta pulsa '1' &quot;))
          print(&quot;\n############\n&quot;)
      f.close()
          
  elif eleccion == 3:
      print(&quot;Ha seleccionado leer todo el listado...\n&quot;)
      f = open('ingles.json')
    
      data = json.load(f)
  
      
      for i in data:
          resta = 20 - len(str(i[&quot;Esp&quot;]))
          vacio = &quot;&quot;
          for n in range(resta):
              vacio += &quot; &quot; 
          print(&quot;                         &quot; + str(i[&quot;Esp&quot;]) + vacio +&quot;|        &quot;+ str(i[&quot;Ing&quot;]))
        
      # Closing file
      f.close()
  </code></pre>
  <p>One example of what could be in ingles.json is:</p>
  <p>[
  {
  &quot;Esp&quot;: &quot;Hola&quot;,
  &quot;Ing&quot;: &quot;Hello&quot;,
  &quot;Complicado&quot;: 0
  },
  {
  &quot;Esp&quot;: &quot;Pedro&quot;,
  &quot;Ing&quot;: &quot;Peter&quot;,
  &quot;Complicado&quot;: 0
  },
  ]</p>