keep tracking time in while loop and interacting with other commands in python3
<p>So i created a while loop that the user input and an output is returned</p>

<pre><code>choice = input()
while True:
    if choice == "Mark":
       print("Zuckerberg")
    elif choice == "Sundar":
       print("Pichai")
</code></pre>

<p>and i want to keep time so when i hit Facebook is going to keep time for FB and when i type Google is going to keep time for google like this</p>

<pre><code>import time
choice = input()
while True:
    if choice == "Facebook":
       endb = time.time()
       starta = time.time()
    if choice == "google":
       enda = time.time()
       startb = time.time()
    if choice == "Mark":
       print("Zuckerberg")
    elif choice == "Sundar":
       print("Pichai")
</code></pre>

<p>if i make this like above when i get to print the elapsed time is going to print
the same number but is going to be minus instead of plus, and vice versa</p>

<pre><code>elapseda = enda - starta
elapsedb = endb - startb
print(elapseda)
print(elapsedb)
</code></pre>

<p>How do i keep track of the time but be able to interact with my other input/outputs?</p>

<p>Thanks</p>

<p>##############################################################################</p>

<p>Edit: Sorry for making it not clear. What i meant by tracking time it that instead of print an output when you type a keyword is going to track time. This will be used to take the possession time of a sport match but meanwhile count other stats like Penalty Kicks and stuff. I cant post my code due to character limit but here is an idea:</p>

<pre><code>while True:
   choice = input()
   if choice == "pk":
      print("pk")
   elif choice == "fk":
      print("fk")
   elif choice == "q":
      break
</code></pre>

<p>and in there i should put possession time but meanwhile i want to interact with the others</p>

<p>In the while loop you could count seconds like so.</p>

<pre><code>import time
a = 0
while True:
    a = a + 1
    time.sleep(1)
</code></pre>

<p>That would mean that a is about how many seconds it look to do the while loop.</p>

python python-3.x input time while-loop