repl.it
@AlexanderSmith8/

Number gueesing game

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import random

def get_a_number():
  number = int(input("Enter a number from 1 to 100: "))
  while number < 1 or number > 100:
    print("That's not correct")
    number = int(input("Enter a number from 1 to 100: "))
  return number

random_number = random.randint(1, 100)
print(random_number)
guess = get_a_number()
tries = 1
while random_number != guess:
  if guess < random_number:
    print("Too low.")
  else:
    print("Too high.")
  guess = int(input("Enter another number from 1 to 100: "))
  tries += 1

print("You win!")
print(f"It took you {tries} to guess the number!")