File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 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!' )
You can’t perform that action at this time.
0 commit comments