Skip to content

Commit 0b30671

Browse files
committed
exercicios sobre funções
1 parent 4d4129a commit 0b30671

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

classes/dogs.py

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
class Dog():
2+
"Uma tentativa de modelar um cachorro"
3+
4+
def __init__(self, name, age):
5+
"""Inicializa os atributos name a age."""
6+
self.name = name
7+
self.age = age
8+
9+
def sit(self):
10+
"""Simula um cachorro sentando em resposta a um commando."""
11+
print(f'{self.name.title()} is now sitting!')
12+
13+
def roll_over(self):
14+
"""Simula um cachorro sentando em resposta a um commando."""
15+
print(f'{self.name.title()} rolled over!')
16+
17+
my_dog = Dog('Kalinda', 6)
18+
print(my_dog)
19+
print(my_dog.name)
20+
print(my_dog.age)
21+
22+
23+
print(f"My dog's name is {my_dog.name.title()}, she is {my_dog.age} years old.")
24+
25+
my_dog.roll_over()
26+
my_dog.sit()
27+

classes/exercicios_classes.py

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
"""9.1 – Restaurante: Crie uma classe chamada Restaurant. O método __init__() de Restaurant deve armazenar dois
2+
atributos: restaurant_name e cuisine_type. Crie um método chamado describe_restaurant() que mostre essas duas
3+
informações, e um método de nome open_restaurant() que exiba uma mensagem informando que o restaurante está aberto.
4+
Crie uma instância chamada restaurant a partir de sua classe. Mostre os dois atributos individualmente e, em seguida,
5+
chame os dois métodos. """
6+
7+
8+
class Restaurant():
9+
def __init__(self, restaurant_name, cuisine_type):
10+
self.restaurant_name = restaurant_name
11+
self.cuisine_type = cuisine_type
12+
13+
def describe_restaurant(self):
14+
print(f'O restaurante {self.restaurant_name} possui culinária {self.cuisine_type}.')
15+
16+
def open_restaurant(self):
17+
print('O restaurante está aberto!')
18+
19+
20+
restaurante = Restaurant('Amadeus', 'Síria')
21+
print(restaurante.restaurant_name)
22+
print(restaurante.cuisine_type)
23+
restaurante.describe_restaurant()
24+
restaurante.open_restaurant()
25+
26+
"""9.2 – Três restaurantes: Comece com a classe do Exercício 9.1. Crie três instâncias diferentes da classe e chame
27+
describe_restaurant() para cada instância. """
28+
29+
restaurante_matriz = Restaurant('Baora', 'Sul-Africana')
30+
restaurante_filial_01 = Restaurant('Amon', 'Egípcia')
31+
restaurante_filial_02 = Restaurant('Zulu', 'da Costa do Marfim')
32+
33+
restaurante_matriz.describe_restaurant()
34+
restaurante_filial_01.describe_restaurant()
35+
restaurante_filial_02.describe_restaurant()
36+
37+
"""9.3 – Usuários: Crie uma classe chamada User. Crie dois atributos de nomes first_name e last_name e, então,
38+
crie vários outros atributos normalmente armazenados em um perfil de usuário. Escreva um método de nome
39+
describe_user() que apresente um resumo das informações do usuário. Escreva outro método chamado greet_user() que
40+
mostre uma saudação personalizada ao usuário. Crie várias instâncias que representem diferentes usuários e chame os
41+
dois métodos para cada usuário. """
42+
43+
44+
class User():
45+
def __init__(self, first_name, last_name, user_name, departament):
46+
self.first_name = first_name
47+
self.last_name = last_name
48+
self.user_name = user_name
49+
self.departament = departament
50+
51+
def describe_user(self):
52+
print(f'{self.first_name} {self.last_name}, seu nome de usuário é {self.user_name} e seu departa'
53+
f'mento é {self.departament}.')
54+
55+
def greet_user(self):
56+
print(f'Bem-vindo {self.user_name}!')
57+
58+
59+
usuario = User('Hugo', 'Gusmão', 'hugonbgg', 'Engenharia')
60+
print(usuario.user_name, usuario.last_name, usuario.user_name, usuario.departament)
61+
usuario.describe_user()
62+
usuario.greet_user()

0 commit comments

Comments
 (0)