forked from LewisAndClark-CSD/Chapter_3
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathChallenge4.py
More file actions
42 lines (30 loc) · 961 Bytes
/
Challenge4.py
File metadata and controls
42 lines (30 loc) · 961 Bytes
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
32
33
34
35
36
37
38
39
40
41
42
# Guess My Number
#
# The player picks a random number between 1 and 100
# The computer tries to guess it and the player lets
# the computer know if the guess is too high, too low
# or right on the money
import random
print("\tWelcome to 'Guess Your Number'!")
print("\nI want you to think of a number between 1 and 100.")
print("I'll try to guess it in as few attempts as possible.\n")
# set the initial values
number = int(input("Enter your number: "))
guess = random.randint(1,100)
print(guess)
tries = 1
highest = 100
lowest = 0
# guessing loop
while guess != number:
x = input("Do i need to go higher or lower? ")
if x == "lower":
highest = guess - 1
elif x == "higher":
lowest = guess + 1
guess = random.randint(lowest, highest)
print(guess)
tries += 1
print("I guessed it! The number was", number)
print("And it only took me", tries, "tries!\n")
input("\n\nPress the enter key to exit.")