Numbers & operators · Números & operadores
Two kinds of number
- An integer (
int) is a whole number, like7or-3. - A float is a number with a decimal point, like
2.5. - Division with
/always gives a float, even4 / 2→2.0.
Dois tipos de número
- Um inteiro (
int) é um número inteiro, como7ou-3. - Um float (ponto flutuante) é um número com ponto decimal, como
2.5. - A divisão com
/sempre resulta em float, mesmo4 / 2→2.0.
Add, subtract, multiply, divide
+adds,-subtracts,*multiplies,/divides.- You can use them with variables or with plain numbers.
- Spaces around operators are optional but make code easier to read.
Somar, subtrair, multiplicar, dividir
+soma,-subtrai,*multiplica,/divide.- Você pode usá-los com variáveis ou com números simples.
- Espaços ao redor dos operadores são opcionais, mas facilitam a leitura do código.
print(7 + 2)
print(7 - 2)
print(7 * 2)
print(7 / 2)
Whole-number division, remainder, powers
//divides and keeps only the whole part (floor division).%gives the remainder (called modulo).**raises to a power:2 ** 3is 2×2×2.
Divisão inteira, resto, potências
//divide e mantém apenas a parte inteira (divisão de piso).%dá o resto (chamado módulo).**eleva a uma potência:2 ** 3é 2×2×2.
print(7 // 2)
print(7 % 2)
print(2 ** 5)
Order of operations
- Python does
**first, then*///%, then+-. - This is the same order you use in maths.
- Use parentheses
(...)to change the order.
Ordem de operações
- Python executa
**primeiro, depois*///%, então+-. - Esta é a mesma ordem que você usa na matemática.
- Use parênteses
(...)para alterar a ordem.
print(2 + 3 * 4)
print((2 + 3) * 4)
Common mistakes
/always gives a float (4 / 2is2.0); use//when you want a whole number.- Power is
**, not^. "3" + "4"joins text into"34"— it does not add to7.
Erros comuns
/sempre retorna um float (4 / 2é2.0); use//quando quiser um número inteiro.- Potência é
**, não^. "3" + "4"junta textos em"34"— ele não soma a7.
Now you try
- Store each answer in the variable named in the task.
- Press Check answer to test your code.
Agora você tenta
- Armazene cada resposta na variável nomeada na tarefa.
- Clique em Check answer para testar seu código.
Order of operations · Ordem de operações
Python evaluates × and ÷ before + and −, left to right. · Python avalia × e ÷ antes de + e −, da esquerda para a direita.
Set · Definir length to · até 8 and · e width to · até 5. Then store their product in a variable called area. · Defina length como 8 e width como 5. Então armazene seu produto em uma variável chamada area.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
You share 17 sweets among 5 children. Store how many each · cada child gets in each (use //), and how many are left over in left (use %). · Você divide 17 doces entre 5 crianças. Armazene quantos cada criança recebe em each (use //), e quantos ficam sobrando em left (use %).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Store 3 ** 2 + 1 in result. Then use parentheses to store (3 + 1) ** 2 in grouped. · Armazene 3 ** 2 + 1 em result. Depois use parênteses para armazenar (3 + 1) ** 2 em grouped.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
celsius is 37. Store the temperature in Fahrenheit in fahrenheit, using the formula celsius × 9 ÷ 5 + 32. · celsius é 37. Armazene a temperatura em Fahrenheit em fahrenheit, usando a fórmula celsius × 9 ÷ 5 + 32.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.