-
Notifications
You must be signed in to change notification settings - Fork 690
/
Higher_Lower.py
31 lines (25 loc) · 1011 Bytes
/
Higher_Lower.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3
import random
number = random.randint(1, 10)
tries = 0
win = False # setting a win flag to false
name = input("Hello, What is your username?")
print("Hello " + name + "." )
question = input("Would you like to play a game? [Y/N] ")
if question.lower() == "n": #in case of capital letters is entered
print("oh..okay")
exit()
if question.lower() == "y":
print("I'm thinking of a number between 1 & 10")
while not win: # while the win is not true, run the while loop. We set win to false at the start therefore this will always run
guess = int(input("Have a guess: "))
tries = tries + 1
if guess == number:
win = True # set win to true when the user guesses correctly.
elif guess < number:
print("Guess Higher")
elif guess > number:
print("Guess Lower")
# if win is true then output message
print("Congrats, you guessed correctly. The number was indeed {}".format(number))
print("it had taken you {} tries".format(tries))