Skip to content

Instantly share code, notes, and snippets.

@MisterBrash
Created October 24, 2023 18:13
Show Gist options
  • Save MisterBrash/923501496dc8d37840301dc109dbafaf to your computer and use it in GitHub Desktop.
Save MisterBrash/923501496dc8d37840301dc109dbafaf to your computer and use it in GitHub Desktop.
Guessing Game demonstration given in class on October 24th
import unicornhathd as u
import random
# Clear the unicorn hat
u.off()
# Generate a random number
hidden_number = random.randint(1, 10)
user_guess = -1
while (user_guess != hidden_number):
# Asked the user for a guess
user_guess = input("Please guess a number from 1 to 10: ")
user_guess = int(user_guess)
# Check if the guess was correct
if hidden_number == user_guess:
print("Congratulations, you guessed the right number!")
u.set_all(0, 255, 0)
elif (user_guess > hidden_number):
print("Too high.")
u.set_all(255, 0, 0)
else:
u.set_all(0, 0, 255)
print("Too low.")
u.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment