|
18 | 18 | },
|
19 | 19 | {
|
20 | 20 | "cell_type": "code",
|
21 |
| - "execution_count": null, |
| 21 | + "execution_count": 2, |
22 | 22 | "metadata": {
|
23 | 23 | "collapsed": false
|
24 | 24 | },
|
25 |
| - "outputs": [], |
| 25 | + "outputs": [ |
| 26 | + { |
| 27 | + "name": "stdout", |
| 28 | + "output_type": "stream", |
| 29 | + "text": [ |
| 30 | + "10 0\n", |
| 31 | + "10 1\n" |
| 32 | + ] |
| 33 | + } |
| 34 | + ], |
26 | 35 | "source": [
|
27 | 36 | "# Exercício 1 - Crie um objeto a partir da classe abaixo, chamado roc1, passando 2 parâmetros e depois faça uma chamada\n",
|
28 | 37 | "# aos atributos e métodos\n",
|
|
40 | 49 | " \n",
|
41 | 50 | " def print_rocket(self):\n",
|
42 | 51 | " print(self.x, self.y)\n",
|
43 |
| - " rocket1 = Rocket(10,0) |
44 |
| - "rocket1.print_rocket()" |
45 |
| - "rocket1.x" |
46 |
| - "rocket1.y" |
47 |
| - "rocket1.move_rocket()" |
48 |
| - "rocket1.print_rocket()" |
| 52 | + " \n", |
| 53 | + "rocket1 = Rocket(10,0)\n", |
| 54 | + "rocket1.print_rocket()\n", |
| 55 | + "rocket1.x\n", |
| 56 | + "rocket1.y\n", |
| 57 | + "rocket1.move_rocket()\n", |
| 58 | + "rocket1.print_rocket()\n", |
| 59 | + " " |
49 | 60 | ]
|
50 | 61 | },
|
51 | 62 | {
|
52 | 63 | "cell_type": "code",
|
53 |
| - "execution_count": null, |
| 64 | + "execution_count": 5, |
54 | 65 | "metadata": {
|
55 | 66 | "collapsed": false
|
56 | 67 | },
|
57 |
| - "outputs": [], |
| 68 | + "outputs": [ |
| 69 | + { |
| 70 | + "name": "stdout", |
| 71 | + "output_type": "stream", |
| 72 | + "text": [ |
| 73 | + "nome: Joao, idade: 35 anos, cidade: Poa, tel: 80 9 9377 0034\n" |
| 74 | + ] |
| 75 | + } |
| 76 | + ], |
58 | 77 | "source": [
|
59 | 78 | "# Exercício 2 - Crie uma classe chamada Pessoa() com os atributos: nome, cidade, telefone e e-mail. Use pelo menos 2\n",
|
60 | 79 | "# métodos especiais na sua classe. Crie um objeto da sua classe e faça uma chamada a pelo menos um dos seus métodos\n",
|
61 |
| - "# especiais\n" |
| 80 | + "# especiais\n", |
| 81 | + "\n", |
| 82 | + "class Pessoas():\n", |
| 83 | + " def __init__(self, nome, idade, cidade, telefone):\n", |
| 84 | + " self.nome = nome\n", |
| 85 | + " self.idade = idade\n", |
| 86 | + " self.cidade = cidade\n", |
| 87 | + " self.telefone = telefone\n", |
| 88 | + " \n", |
| 89 | + " def __str__(self):\n", |
| 90 | + " return (\"nome: %s, idade: %i anos, cidade: %s, tel: %s\" %(self.nome, self.idade, self.cidade, self.telefone))\n", |
| 91 | + " \n", |
| 92 | + " \n", |
| 93 | + "Joao = Pessoas('Joao', 35, 'Poa', '80 9 9377 0034')\n", |
| 94 | + "\n", |
| 95 | + "print (Joao)\n", |
| 96 | + "\n", |
| 97 | + "\n", |
| 98 | + "\n", |
| 99 | + "\n", |
| 100 | + "\n", |
| 101 | + " " |
62 | 102 | ]
|
63 | 103 | },
|
64 | 104 | {
|
65 | 105 | "cell_type": "code",
|
66 |
| - "execution_count": null, |
| 106 | + "execution_count": 6, |
67 | 107 | "metadata": {
|
68 | 108 | "collapsed": false
|
69 | 109 | },
|
|
73 | 113 | "# atributos capacidade. A classe MP3player deve herdar os atributos da classe Smartphone.\n"
|
74 | 114 | ]
|
75 | 115 | },
|
| 116 | + { |
| 117 | + "cell_type": "code", |
| 118 | + "execution_count": 8, |
| 119 | + "metadata": { |
| 120 | + "collapsed": false |
| 121 | + }, |
| 122 | + "outputs": [ |
| 123 | + { |
| 124 | + "name": "stdout", |
| 125 | + "output_type": "stream", |
| 126 | + "text": [ |
| 127 | + "2\n" |
| 128 | + ] |
| 129 | + } |
| 130 | + ], |
| 131 | + "source": [ |
| 132 | + "class Smartphone():\n", |
| 133 | + " def __init__(self, tamanho, interface):\n", |
| 134 | + " self.tamanho = tamanho\n", |
| 135 | + " self.interface = interface\n", |
| 136 | + " def __str__(self):\n", |
| 137 | + " return __\n", |
| 138 | + "\n", |
| 139 | + "class Mp3player(Smartphone):\n", |
| 140 | + " def __init__(self, capacidade, interface, tamanho):\n", |
| 141 | + " Smartphone.__init__(self, interface, tamanho)\n", |
| 142 | + " self.capacidade = capacidade\n", |
| 143 | + "\n", |
| 144 | + "\n", |
| 145 | + "xingling_player = Mp3player(interface = \"lolipop\", tamanho = 5.5, capacidade = 2)\n", |
| 146 | + "\n", |
| 147 | + "print (xingling_player.capacidade)\n" |
| 148 | + ] |
| 149 | + }, |
76 | 150 | {
|
77 | 151 | "cell_type": "markdown",
|
78 | 152 | "metadata": {},
|
|
104 | 178 | "name": "python",
|
105 | 179 | "nbconvert_exporter": "python",
|
106 | 180 | "pygments_lexer": "ipython3",
|
107 |
| - "version": "3.5.1" |
| 181 | + "version": "3.6.0" |
108 | 182 | }
|
109 | 183 | },
|
110 | 184 | "nbformat": 4,
|
|
0 commit comments