AdSense

Friday, December 29, 2017

Python: Number Guessing Game

# number guessing game

import random

# random numbers from 1 to 100
secret_number = random.randint(1, 100)

# your guess
guess = 0

# number of guess
tries = 0
max_tries = 7

print("Welcome to the number guessing game.")
print("I am thinking of a number between 1 and 100.")
print("I will give " + str(max_tries) + " tries to get it. Good luck!")

while (guess != secret_number) and (tries <  max_tries):

guess = int(input("What is your guess? "))

if guess > secret_number:
print("That is too HIGH.")

elif guess < secret_number:
print("That is too LOW.")

tries = tries + 1


if guess == secret_number:

print("You guessed my number!")
print("##############################")
print("       Congratulations!       ")
print("##############################")

else:

print("Better luck next time")
print("The secret number was", secret_number)

Reference:
https://youtu.be/7CTONNO6YMc

No comments:

Post a Comment

Deep Learning (Regression, Multiple Features/Explanatory Variables, Supervised Learning): Impelementation and Showing Biases and Weights

Deep Learning (Regression, Multiple Features/Explanatory Variables, Supervised Learning): Impelementation and Showing Biases and Weights ...