title: Python: How to get else statement to run x number of times?
body: <p>I have a script to telnet router and if it can't ping 8.8.8.8 to reboot router, but I don't want it to reboot the router more than three times in a row.
  If it fails to ping 8.8.8.8 after three times I want it to keep pinging 8.8.8.8 until it comes back up again and start all over again.</p>
  
  <pre><code>import subprocess
  output = subprocess.call('ping 8.8.8.8', shell=True)
  while output == 0:
  output = subprocess.call('ping 8.8.8.8', shell=True)
  else:
  import telnetlib
  import datetime
  
  now = datetime.datetime.now()
  
  host = "912.168.1.1" # your router ip
  username = "name" # the username
  password = "password"
  filename_prefix = "cisco-backup"
  
  tn = telnetlib.Telnet(host)
  tn.read_until("Username:")
  tn.write(username+"\n")
  tn.read_until("Password:")
  tn.write(password+"\n")
  tn.write("reload"+"\n")
  tn.write("y"+"\n")
  enter code here
  </code></pre>
  
  <p>I'm only new at this and I don't know how to get the else statement to only repeat three times in a row.</p>