Skip to content

Commit b6e2b86

Browse files
committed
exercicios sobre instancias
1 parent 4ee7c09 commit b6e2b86

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

classes/exercicios_instancias.py

+36-2
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def increment_number_served(self, incrimento):
3737
self.number_served += incrimento
3838

3939

40-
restaurante = Restaurant('Halim', 'Árabe')
40+
'''restaurante = Restaurant('Halim', 'Árabe')
4141
restaurante.describe_restaurant()
4242
restaurante.number_served = 23
4343
@@ -51,11 +51,45 @@ def increment_number_served(self, incrimento):
5151
restaurante.read_number_served()
5252
5353
restaurante.increment_number_served(100)
54-
restaurante.read_number_served()
54+
restaurante.read_number_served()'''
5555

5656
"""9.5 – Tentativas de login: Acrescente um atributo chamado login_attempts à sua classe User do Exercício 9.3 (
5757
página 226). Escreva um método chamado increment_login_attempts() que incremente o valor de login_attempts em 1.
5858
Escreva outro método chamado reset_login_attempts() que reinicie o valor de login_attempts com 0. Crie uma instância
5959
da classe User e chame increment_login_attempts() várias vezes. Exiba o valor de login_attempts para garantir que ele
6060
foi incrementado de forma apropriada e, em seguida, chame reset_login_attempts(). Exiba login_attempts novamente para
6161
garantir que seu valor foi reiniciado com 0. """
62+
63+
64+
class User():
65+
def __init__(self, first_name, last_name, user_name, departament):
66+
self.first_name = first_name
67+
self.last_name = last_name
68+
self.user_name = user_name
69+
self.departament = departament
70+
self.login_attempts = 0
71+
72+
def describe_user(self):
73+
print(f'{self.first_name} {self.last_name}, seu nome de usuário é {self.user_name} e seu departa'
74+
f'mento é {self.departament}. Atualmente foram feitas {self.login_attempts} tentativas de login.')
75+
76+
def greet_user(self):
77+
print(f'Bem-vindo {self.user_name}!')
78+
79+
def increment_login_attempts(self):
80+
self.login_attempts += 1
81+
82+
def reset_login_attempts(self):
83+
self.login_attempts = 0
84+
print("Tentivas de login resetadas!")
85+
86+
87+
usuario = User('Hugo', 'Gusmão', 'hugonbgg', 'Data Engineer')
88+
89+
usuario.describe_user()
90+
while usuario.login_attempts < 10:
91+
usuario.increment_login_attempts()
92+
usuario.describe_user()
93+
usuario.reset_login_attempts()
94+
usuario.describe_user()
95+

classes/herancas.py

Whitespace-only changes.

0 commit comments

Comments
 (0)