-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathguess.py
More file actions
35 lines (25 loc) · 745 Bytes
/
guess.py
File metadata and controls
35 lines (25 loc) · 745 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
"""Guess a number within a range.
Exercises
1. Change the range to be from 0 to 1,000,000.
2. Can you still guess the number?
3. Print the number of guesses made.
4. Limit the number of guesses to the minimum required.
"""
from random import randint
sayac=0
while True:
start = 1
end = 100
value = randint(start, end)
print("I'm thinking of a number between", start, "and", end)
guess = None
while guess != value:
text = input("Guess the number: ")
guess = int(text)
sayac=sayac+1
if guess < value:
print("Higher.")
elif guess > value:
print("Lower.")
print("Congratulations! You guessed the right answer:", value)
print(sayac,"attempts")