Simple Keyboard Racing with Python Last Updated : 21 Jul, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report Let's make a simple keyboard racing game using Python. In the game, the participant clicks a pair of keys in quick succession and the program shows the total time taken by the racer to cover the distance. Rules: As soon as you see 'GO!' on screen, start pressing the keys 'z' and 'x'. A '*' sign is shown for every meter covered. Pressing 'z' and 'x' once will be counted as 1 meter; targets is to cover 10 meters. Modules Used: msvcrt : Used to get keystroke as input for race time : Used to calculate time taken to complete the race Note that MSVCRT module can only function on a terminal window, not on a GUI program/IDE. Below is the code: Python3 import msvcrt import time high_score = 17.78 name = "GeeksforGeeks" while True: distance = int(0) print('\n--------------------------------------------------------------') print('\n\nWelcome to the 100m sprint, tap z and x rapidly to move!') print('* = 10m') print('\nCurrent record:' + str(high_score) + ' by: ' + name) print('\nPress enter to start') input() print('Ready...') time.sleep(1) print('GO!') start_time = time.time() while distance < 10: k1 = msvcrt.getch().decode('ASCII') if k1 == 'z': k2 = msvcrt.getch().decode('ASCII') if k2 == 'x': distance += 1 if distance == 5: print("* You're halfway there!") elif distance % 1 == 0: print('*') fin_time = time.time() - start_time fin_time = round(fin_time, 2) print('Congratulations on successfully completing the race!') print('You took', fin_time, 'seconds to reach the finish line') if fin_time < high_score: print("Well done you've got a new high score ") name = input("Please enter your name : ") high_score = fin_time Output: Game InitiateGame in ProgressGame Finished: New High Score Comment More infoAdvertise with us Next Article Simple Keyboard Racing with Python R rajatg98 Follow Improve Article Tags : Python Python Programs Practice Tags : python Similar Reads Spiral Sprint Game in Python Using Pygame In this article, we will see how to create a spiral sprint game in Python using Pygame. In this game, we will have functionality like difficulty modes, obstacle crashing, speed increment when points are increased, scoreboard, Particle animation, color-changing orbits, coins, and game sounds. Spiral 15+ min read Create a simple Animation using Turtle in Python Turtle is a built-in Python module that provides a simple way to draw and create graphics using a virtual turtle on the screen. You can control the turtle using commands like forward() and right() to move it around and draw shapes. In this article, we'll use Turtle to create a fun animation where mu 2 min read Python Exercise with Practice Questions and Solutions Python Exercise for Beginner: Practice makes perfect in everything, and this is especially true when learning Python. If you're a beginner, regularly practicing Python exercises will build your confidence and sharpen your skills. To help you improve, try these Python exercises with solutions to test 9 min read Measure time taken by program to execute in Python Measuring the execution time of a Python program is useful for performance analysis, benchmarking, and optimization. Python provides several built-in modules to achieve this with ease. In this article, we'll explore different ways to measure how long a Python program takes to run.Using the time Modu 2 min read Google Chrome Dino Bot using Image Recognition | Python What would you see in your Chrome browser when there is no internet connection? Yes, everybody knows that dinosaur game that comes on screen. So, in this article, we are going to build a simple python bot that plays Chrome Dino Game without user interaction. Here we are not using any machine learnin 4 min read Like