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
28 changes: 28 additions & 0 deletions Python/guess_number.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import random

random_number = random.randint(0, 100)
print("Hello, What is your name?")
my_name = input()
print("Hi, {}! We will be playing a guessing game.".format(my_name))
print("Well, {} I am thinking of a number between 1 to 99".format(my_name))
print("You have to guess it in 7 chances.")
chances = 0
for gusses in range(1, 7):
print("Take a guess")
guess = int(input())
chances += 1
if guess > random_number:
print("Your number is too high!")
elif guess < random_number:
print("Your number is too low!")
else:
break

if random_number == guess:
print(
"Good job {}, You guessed the number in {} chances, I was thinking of {}".format(
my_name, chances, random_number
)
)
else:
print("Oops, You Lost! I was thinking of {}".format(random_number))