Created
March 8, 2023 18:40
-
-
Save R3DHULK/e637a527a050ef017cc074dfa363c620 to your computer and use it in GitHub Desktop.
Text Based Simon Says Written In Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import time | |
def simon_says(): | |
# Define the colors | |
colors = ["red", "green", "blue", "yellow"] | |
# Keep track of the sequence | |
sequence = [] | |
while True: | |
# Add a new color to the sequence | |
sequence.append(random.choice(colors)) | |
# Show the sequence | |
print("Simon says:", end=" ") | |
for color in sequence: | |
print(color, end=" ", flush=True) | |
time.sleep(1) | |
print() | |
# Ask the user to repeat the sequence | |
print("Repeat the sequence:") | |
for color in sequence: | |
guess = input() | |
if guess != color: | |
print("Game over!") | |
return | |
print("Correct!") | |
if __name__ == "__main__": | |
simon_says() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment