-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadivinhe.py
More file actions
62 lines (52 loc) · 1.87 KB
/
adivinhe.py
File metadata and controls
62 lines (52 loc) · 1.87 KB
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# importando bibliotecas
from random import randint
import os
# funcão que mostra o cabeçalho
def start_layout():
print("=======================================")
print("----------Adivinhe se puder------------")
print("=======================================")
start_game()
# função que gera o valor aleatório
def generate_value():
number = randint(0, 100)
return number
#função que testa se o usuário quer continuar
def restart_game():
restart = input("Deseja jogar novamente? Responda com 'sim/nao: ")
if restart.lower() == "sim":
os.system("cls")
start_layout()
elif restart.lower() == "nao":
print("Até mais!!!")
exit()
else:
print("Desculpe valor invalido. tente novamente somente com 'sim/nao'")
restart_game()
# função que principal
def start_game():
global user
value_true = generate_value()
# laço que repete as entradas do usuario até ele acertar
lace = True
while lace == True:
# laço que valida as entradas do usuario
lace2 = True
while lace2 == True:
value_test = input("Chute um numero inteiro entre 0 e 100: ")
if value_test.isdigit() and int(value_test) in range(100 + 1):
user = value_test
lace2 = False
else:
print("valor invalido. tente novamente somente com numeros inteiros entre 0 e 100\n")
#comparador que testa as entradas do usuário
if int(user) == value_true:
print("Parabéns você acertou!!\n")
lace = False
elif int(user) > value_true:
print("Número muito alto, digite um valor menor.\n")
else:
print("valor muito baixo, digite um avlor maior.\n")
restart_game()
# programa principal
start_layout()