-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathex058.py
More file actions
29 lines (22 loc) · 764 Bytes
/
ex058.py
File metadata and controls
29 lines (22 loc) · 764 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
# Refazer o desafio 28, (agora números de 0 a 10)
# para que o usuário fique tentando até acertar e,
# ao final, mostrar o número de palpites necessários
from random import randint
shouldContinue = True
print('Digite -1 para parar.')
while shouldContinue:
numero = randint(0,11)
print('Pensei em um novo número de 0 a 10. Tente acertá-lo!')
nTentativas = 1
digitado = input('>>>\t').strip()
# De forma que digitar uma string não crasha na conversão.
while str(numero) != digitado and digitado != '-1':
digitado = input('>>>\t').strip()
nTentativas += 1
if digitado == '-1':
break
print('Você acertou em {} tentativas!'.format(nTentativas))
if nTentativas < 4:
print('Essa foi boa!')
elif nTentativas > 8:
print('Pouca sorte!')