Skip to content

Commit 2d39788

Browse files
committed
New code
1 parent 2dbf415 commit 2d39788

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

ex058.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Improve the challenge 28 game where the computer will “think” of a number between 0 and 10. But now the player will
2+
#try to guess until you get it right, showing at the end how many guesses it took to win.
3+
from random import randint
4+
computer = randint(0,10)
5+
print('I am your computer. . . I just thought of a number between 0 and 10. ')
6+
print('Can you guess which one it was?')
7+
got_it_right = False
8+
guesses = 0
9+
while not got_it_right:
10+
player = (int(input('What is your guess?')))
11+
guesses +=1
12+
if player == computer:
13+
got_it_right = True
14+
else:
15+
if player < computer:
16+
print('More. Try again.')
17+
elif player > computer:
18+
print('Less. Try again.')
19+
print(f'You got it rigth with {guesses} attempts. Congratulations!')

0 commit comments

Comments
 (0)