Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 30 additions & 13 deletions guess-the-number.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,35 @@
import random
number = random.randint(0, 21)
number_of_guesses = 0
guess = input('I am thinking of a number between 1 and 20. Guess what number I am thinking of: ')
while number_of_guesses < 6:
number_of_guesses += 1
if int(guess) == number:
print('Your guess is correct.')
else:
if int(guess) > number:
print('Your guess is greater than the number I am thinking of.')
elif int(guess) < number:
print('Your guess is less than the number I am thinking of.')
guess = input('Guess again!')

while True:
print("I am thinking of a number between 1 and 20. Guess what number I am thinking of")
number = random.randint(1, 20)

chances = 6

while chances >0:

guess = int(input())

if guess == number:

print("Congratulation YOU WON!!!")
break

elif guess < number:
print("Your guess was too low: Guess a number higher than", guess)

else:
print("Your guess was too high: Guess a number lower than", guess)
chances -= 1

print("Chances Left: ",chances)

if not chances < 10:
print("YOU LOSE!!! The number is", number)

ans = input("Do you want to play again (y/n) : ")

if ans != 'y':
break

print("\n T H A N K S F O R P L A Y I N G ! ! ! ! !\n")