Advertisement
jabela

Untitled

Nov 23rd, 2021
1,280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import datetime
  2. import random
  3. my_string = ""
  4. score = 0
  5. lives = 3
  6.  
  7. while True:
  8.     random_letters = ["a","b","c","d","e","f","g","h","i","j"]
  9.     my_string = my_string + random.choice(random_letters)
  10.  
  11.     start_time = datetime.datetime.now() # Get initial time
  12.     print("Please enter",my_string)
  13.     my_input=input(":")
  14.     finish_time = datetime.datetime.now()    #Get finish time
  15.     reaction_time = finish_time - start_time # difference in time
  16.  
  17.     if my_input == my_string:
  18.         print("\nIt took you:",reaction_time)
  19.         score = score + 10
  20.     else:
  21.         if lives < 1:
  22.             print("Bad luck you failed")
  23.             break #end the loop
  24.         else:
  25.             lives = lives -1
  26.         print("You have",lives)
  27. print("Game over",score)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement