forked from RaspberryPiFoundation/python-curriculum
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6d2185e
commit 9b17067
Showing
77 changed files
with
2,283 additions
and
175 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
pt-BR/lessons/Compliment Generator/Club Leader Resources/PetNamingService.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from random import * | ||
|
||
print("Serviço de escolha de nome para animais de estimação") | ||
print("------------------") | ||
|
||
names = ["Bob", "Fluffy", "Martin", "Spot"] | ||
|
||
#imprime um nome aleatório da lista de nomes | ||
print("Você deve chamar seu animal de estimação de " , choice(names)) |
36 changes: 36 additions & 0 deletions
36
pt-BR/lessons/Compliment Generator/Compliment Generator - notes.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: Gerador de Cumprimentos — Notas para instrutores | ||
language: pt-BR | ||
embeds: "*.png" | ||
... | ||
|
||
#Introdução: | ||
Este projeto ensina as crianças a usar listas, a acessar elementos de uma lista, a adicionar e remover itens de uma lista. Os alunos aprendem por meio de um gerador de cumprimentos, que dá ao usuário um cumprimento aleatório a partir de uma lista. | ||
|
||
#Recursos | ||
Para este projeto, é necessário instalar o Python. É recomendado que a versão 3.2 do Python seja instalada. | ||
|
||
As crianças também podem usar os materiais que acompanham os desafios. Arquivos da pasta 'Project Resources' (encontrada sob o link 'Download Project Materials'): | ||
|
||
+ ComplimentGenerator.py | ||
|
||
Verifique se todas as crianças têm acesso de leitura e escrita às cópias desses recursos. | ||
|
||
Você pode encontrar uma versão completa dos desafios deste projeto clicando no link 'Download Project Materials' para este projeto, que contém: | ||
|
||
+ PetNamingService.py | ||
|
||
#Objetivos de aprendizado | ||
+ Listas; | ||
+ Arrays e acesso a elementos de listas; | ||
+ Uso do método `random.choice()` em uma lista; | ||
+ Métodos `append()` e `remove()` de listas. | ||
|
||
#Desafios | ||
+ Adicione mais cumprimentos - adicione itens a uma lista; | ||
+ Duplicação de hobbies - teste e corrija um problema; | ||
+ Serviço de escolha de nome para animais de estimação - aplique o uso de listas para um novo problema. | ||
|
||
#Perguntas frequentes | ||
+ As crianças podem precisar de ajuda para lembrar que os itens de uma lista são separados por uma vírgula, e que não há vírgula depois do último item de uma lista. | ||
|
262 changes: 262 additions & 0 deletions
262
pt-BR/lessons/Compliment Generator/Compliment Generator.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,262 @@ | ||
--- | ||
title: Gerador de Cumprimentos | ||
level: Python 1 | ||
language: pt-BR | ||
stylesheet: python | ||
embeds: "*.png" | ||
materials: ["Project Resources/*.*","Club Leader Resources/*.*"] | ||
... | ||
|
||
#Introdução: { .intro} | ||
|
||
Aprenda a usar listas para armazenar vários dados em 1 variável. | ||
|
||
#Etapa 1: É legal ser legal { .activity} | ||
|
||
Neste projeto, você vai fazer um programa que dá um cumprimento gerado aleatoriamente para o usuário! | ||
|
||
## Lista de verificação da atividade { .check} | ||
|
||
+ Em seus projetos, até agora você usou uma variável para armazenar um único dado, como um nome ou uma pontuação. Mas e se você quiser armazenar vários dados? Em Python, você pode usar uma _lista_ para armazenar vários dados em 1 variável: | ||
|
||
```python | ||
bigPlanets = [ "júpiter" , "saturno" , "urano" , "netuno"] | ||
``` | ||
|
||
Esta lista de texto também é conhecida como um _array_ de texto. Para acessar itens da lista, você só precisa saber a posição do item. Execute esse programa para ter uma ideia melhor de como as listas funcionam: | ||
|
||
```python | ||
bigPlanets = [ "júpiter" , "saturno" , "urano" , "netuno"] | ||
print( bigPlanets ) | ||
print( bigPlanets[0] ) | ||
print( bigPlanets[1] ) | ||
print( bigPlanets[2] ) | ||
print( bigPlanets[3] ) | ||
``` | ||
|
||
 | ||
|
||
Como você pode ver, as posições começam em 0 e não em 1, então `bigPlanets[1]` é "saturno" (o segundo item) e não "júpiter". | ||
|
||
+ Você pode usar uma lista chamada `cumprimentos` para armazenar todos os cumprimentos possíveis para o seu programa gerador de cumprimentos, e então usar `choice(cumprimentos)` para escolher um cumprimento aleatório para o usuário: | ||
|
||
```python | ||
from random import * | ||
print("Gerador de Cumprimentos") | ||
print("--------------------") | ||
cumprimentos = [ "Excelente trabalho. Realmente muito bem feito." , | ||
"Suas habilidades de programação são muito, muito boas." , | ||
"Você é um humano excelente." | ||
] | ||
#imprime um item aleatório da lista 'cumprimentos' | ||
print(choice(cumprimentos)) | ||
print("De nada!") | ||
``` | ||
|
||
 | ||
|
||
+ Você pode tornar seus cumprimentos um pouco mais interessantes combinando itens aleatórios de 2 listas diferentes: | ||
|
||
```python | ||
from random import * | ||
print("Gerador de Cumprimentos") | ||
print("--------------------") | ||
adjetivos = [ "maravilhoso" , "acima da média" , "excelente" ] | ||
hobbies = [ "andar de bicicleta" , "programar" , "fazer chá" ] | ||
nome = input("Qual é o seu nome?: ") | ||
print( "Aqui está o seu cumprimento" , nome , ":" ) | ||
#obtém um item aleatório de ambas as listas e adiciona-os ao cumprimento | ||
print( nome , "você é" , choice(adjetivos) , "em" , choice(hobbies) ) | ||
print( "De nada!" ) | ||
``` | ||
|
||
 | ||
|
||
## Salve seu projeto {.save} | ||
|
||
## Desafio: Adicione mais cumprimentos { .challenge} | ||
Tente pensar em mais cumprimentos e adicione-os ao seu programa! Lembre-se de que você precisa adicionar uma vírgula (`,`) entre os itens em suas listas. | ||
|
||
## Salve seu projeto {.save} | ||
|
||
#Etapa 2: Cumprimentos sem fim { .activity} | ||
|
||
## Lista de verificação da atividade { .check} | ||
|
||
+ Usando o que você sabe sobre laços `while` (enquanto) e instruções `if` (se), você pode modificar seu programa para continuar dando cumprimentos até que o usuário decida sair: | ||
|
||
```python | ||
from random import * | ||
#o programa continua em execução enquanto a variável for verdadeira 'True' | ||
executa = True | ||
adjetivos = [ "maravilhoso" , "acima da média" , "excelente" ] | ||
hobbies = [ "andar de bicicleta" , "programar" , "fazer chá" ] | ||
print("Gerador de Cumprimentos") | ||
print("--------------------") | ||
nome = input("Qual é o seu nome?: ") | ||
print(''' | ||
Menu | ||
c = obter cumprimento | ||
q = sair | ||
''') | ||
while executa == True: | ||
menuChoice = input("\n>_").lower() | ||
#'c' para um cumprimento | ||
if menuChoice == 'c': | ||
print( "Aqui está o seu cumprimento" , nome , ":" ) | ||
#obtém um item aleatório de ambas as listas e adiciona-os ao cumprimento | ||
print( nome , "você é" , choice(adjetivos) , "em" , choice(hobbies) ) | ||
print( "De nada!" ) | ||
#'q' para sair | ||
elif menuChoice == 'q': | ||
executa = False | ||
else: | ||
print("Escolha uma opção válida!") | ||
``` | ||
|
||
 | ||
|
||
Lembre-se de que o laço `while` continua a ser executado enquanto a variável `executa` for verdadeira `True`. Se o usuário digitar `q` para sair, `executa` é definida como falsa `False`. | ||
|
||
## Salve seu projeto {.save} | ||
|
||
#Etapa 3: Personalização de cumprimentos { .activity} | ||
|
||
## Lista de verificação da atividade { .check} | ||
|
||
+ Seu gerador de cumprimentos está começando a ganhar forma, mas ele tem um problema: e se o usuário não souber andar de bicicleta ou fazer chá? Nesse caso, seus cumprimentos não serão verdadeiros e não vão animá-lo! | ||
|
||
Vamos modificar seu programa, de forma que o usuário possa escolher adicionar ou remover itens da lista de `hobbies`, para que ele possa personalizar os cumprimentos recebidos: | ||
|
||
```python | ||
from random import * | ||
executa = True | ||
adjetivos = [ "maravilhoso" , "acima da média" , "excelente" ] | ||
hobbies = [ "andar de bicicleta" , "programar" , "fazer chá" ] | ||
print("Gerador de Cumprimentos") | ||
print("--------------------") | ||
nome = input("Qual é o seu nome?: ") | ||
print(''' | ||
Menu | ||
c = obter cumprimento | ||
a = adicionar hobby | ||
d = remover hobby | ||
p = imprimir hobbies | ||
q = sair | ||
''') | ||
while executa == True: | ||
menuChoice = input("\n>_").lower() | ||
#'c' para um cumprimento | ||
if menuChoice == 'c': | ||
print( "Aqui está o seu cumprimento" , nome , ":" ) | ||
#obtém um item aleatório de ambas as listas e adiciona-os ao cumprimento | ||
print( nome , "você é" , choice(adjetivos) , "em" , choice(hobbies) ) | ||
print( "De nada!" ) | ||
#'a' para adicionar hobby | ||
elif menuChoice == 'a': | ||
itemToAdd = input("Adicione o hobby: ") | ||
hobbies.append(itemToAdd) | ||
#'d' para remover um hobby | ||
elif menuChoice == 'd': | ||
itemToDelete = input("Insira o hobby a ser removido: ") | ||
hobbies.remove(itemToDelete) | ||
#'p' para imprimir a lista de hobbies | ||
elif menuChoice == 'p': | ||
print(hobbies) | ||
#'q' para sair | ||
elif menuChoice == 'q': | ||
executa = False | ||
else: | ||
print("Insira uma opção válida!") | ||
``` | ||
|
||
Como você pode ver, você pode usar `append()` para adicionar a uma lista, e `remove()` para remover um item. Execute esse programa e personalize os hobbies na lista para que eles sirvam para você. Peça ao programa que cumprimente você até que fique de bom humor! | ||
|
||
+ Quando testou o programa acima, você encontrou algum problema? No momento, seu gerador de cumprimentos para de funcionar se você tentar remover um cumprimento que não está na lista: | ||
|
||
 | ||
|
||
Você pode consertar esse problema, primeiro verificando se o item a ser removido existe na lista. Substitua seu código para remover um hobby por este código: | ||
|
||
```python | ||
#'d' para remover um hobby | ||
elif menuChoice == 'd': | ||
itemToDelete = input("Insira o hobby a ser removido: ") | ||
#só remove um item se ele estiver na lista | ||
if itemToDelete in hobbies: | ||
hobbies.remove(itemToDelete) | ||
else: | ||
print("O hobby não está na lista!") | ||
``` | ||
|
||
Agora, execute o programa e tente remover um hobby que não está na lista: | ||
|
||
 | ||
|
||
## Salve seu projeto {.save} | ||
|
||
## Desafio: Duplicação de hobbies { .challenge} | ||
Outro problema com o programa é que é possível adicionar o mesmo hobby mais de uma vez: | ||
|
||
 | ||
|
||
Você consegue resolver esse problema? Assim, um hobby só pode ser adicionado se ele ainda não estiver na lista: | ||
|
||
```python | ||
if itemToAdd not in hobbies: | ||
#adicione o código aqui... | ||
``` | ||
|
||
## Salve seu projeto {.save} | ||
|
||
## Desafio: Serviço de escolha de nome para animais de estimação { .challenge} | ||
Escreva um programa para ajudar um novo dono a dar nome ao seu animal de estimação: | ||
|
||
 | ||
|
||
Seu programa pode: | ||
+ permitir que o usuário adicione e remova itens da lista; | ||
+ dar nomes diferentes para animais machos e fêmeas, ou para tipos diferentes de animais; | ||
+ perguntar ao usuário quantos nomes eles precisam, caso eles tenham mais de um animal de estimação para dar nome. | ||
|
||
## Salve seu projeto {.save} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import random | ||
|
||
print("Gerador de Cumprimentos") | ||
print("--------------------") | ||
|
||
cumprimentos = [ "Excelente trabalho. Realmente muito bem feito." , | ||
"Suas habilidades de programação são muito, muito boas." , | ||
"Você é um humano excelente." | ||
] | ||
|
||
#imprime um item aleatório da lista 'cumprimentos' | ||
print(random.choice(cumprimentos)) | ||
print("De nada!") |
13 changes: 13 additions & 0 deletions
13
pt-BR/lessons/Compliment Generator/Project Resources/ComplimentGenerator.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from random import * | ||
|
||
print("Compliment Generator") | ||
print("--------------------") | ||
|
||
compliments = [ "Great job on that thing you did. Really super." , | ||
"You have really really nice programming skills." , | ||
"You make an excellent human." | ||
] | ||
|
||
#print a random item in the 'compliments' list | ||
print(choice(compliments)) | ||
print("You're welcome!") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
42 changes: 42 additions & 0 deletions
42
pt-BR/lessons/Gameshow/Club Leader Resources/KeepingScore.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from random import * | ||
|
||
#print the 3 doors and the game instructions | ||
print(''' | ||
Gameshow! | ||
========= | ||
There's a prize behind one of the 3 doors! | ||
Guess the correct door to win the prize! | ||
_____ _____ _____ | ||
| | | | | | | ||
| [1] | | [2] | | [3] | | ||
| o | | o | | o | | ||
|_____| |_____| |_____| | ||
''') | ||
|
||
score = 0 | ||
|
||
#allow the player 3 attempts | ||
for attempt in range(3): | ||
|
||
print("\nChoose a door (1, 2 or 3):") | ||
|
||
#get the chosen door and store it as an integer (whole number) | ||
chosenDoor = input() | ||
chosenDoor = int(chosenDoor) | ||
|
||
#randomly choose the winning door number (between 1 and 3) | ||
winningDoor = randint(1,3) | ||
|
||
#show the player the winning and chosen door numbers | ||
print("The chosen door is", chosenDoor) | ||
print("The winning door is", winningDoor) | ||
|
||
#player wins if the chosen door and winning door number are the same | ||
if chosenDoor == winningDoor: | ||
print("Well done!") | ||
score += 1 | ||
else: | ||
print("Unlucky!") | ||
|
||
print("\nYour final score is", score) |
Oops, something went wrong.