Skip to content

Instantly share code, notes, and snippets.

@neilkuan
Created July 23, 2021 08:34
Show Gist options
  • Save neilkuan/c7e4d5f833516bc28d43ababaa546d4f to your computer and use it in GitHub Desktop.
Save neilkuan/c7e4d5f833516bc28d43ababaa546d4f to your computer and use it in GitHub Desktop.
highlow.py
count = 0
while True:
# Start of game?
if count == 0:
start_time = time.time()
num = random.randint(1, 100)
print "I'm thinking of a number from 1 to 100. Try to guess it! (Enter 0 to exit)"
# Guess a number
guess = input("> ")
count += 1
# Respond
if guess == 0:
# End game
sys.exit()
elif guess < num:
print "Too low!"
elif guess > num:
print "Too high!"
else:
# Correct answer
seconds = int(time.time() - start_time)
print "That's correct! It took you %d guesses and %d seconds.\n" % (count, seconds)
# Push metric to CloudWatch
cloudwatch_client.put_metric_data(Namespace="Lab", MetricData=[{'MetricName':'highlow', 'Value':seconds}])
print "The metric has been sent to CloudWatch.\n"
# Start again
count = 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment