Variables, constants & data types · Variáveis, constantes e tipos de dados
A variable is a named box
- A variable is a name that stores a value.
- You put a value in with
=— this is called assignment. - Use a clear name so the program is easy to read.
Uma variável é uma caixa nomeada
- Uma variável é um nome que armazena um valor.
- Você coloca um valor com
=— isso é chamado de atribuição. - Use um nome claro para que o programa seja fácil de ler.
age = 15
price = 2.50
name = "Ada"
print(age, price, name)
Variables as named boxes · Variáveis como caixas nomeadas
Each · Cada = puts a value into a named box you can use later. · Cada = coloca um valor em uma caixa nomeada que você pode usar depois.
The five data types
- IGCSE uses five basic data types:
- integer (whole number) → Python
int; real (decimal) →float. - char (one letter), string (text) →
str; Boolean (True/False) →bool.
Os cinco tipos de dados
- IGCSE usa cinco tipos de dados básicos:
- integer (número inteiro) → Python
int; real (decimal) →float. - char (uma letra), string (texto) →
str; Boolean (True/False) →bool.
score = 42 # integer
height = 1.75 # real
grade = "A" # char
town = "Cairo" # string
passed = True # Boolean
Constants stay the same
- A constant is a value that never changes while the program runs.
- Python has no special keyword, so we write constants in
CAPITALS. - This warns other readers: do not change me.
Constantes permanecem as mesmas
- Uma constante é um valor que nunca muda enquanto o programa executa.
- Python não tem palavra-chave especial, então escrevemos constantes em
CAPITALS. - Isso avisa outros leitores: não me mude.
PI = 3.14159
VAT_RATE = 0.20
print(PI)
Changing between types
input()gives a string, so convert it when you need a number.int(x)makes a whole number;float(x)a decimal;str(x)makes text.
Alterando entre tipos
input()retorna uma string, então converta quando precisar de um número.int(x)faz um número inteiro;float(x)um decimal;str(x)faz texto.
n = int("5")
print(n + 1) # 6
print("Total: " + str(n)) # Total: 5
In the exam: DECLARE and CONSTANT
- Pseudocode names a type with
DECLARE, and fixes a value withCONSTANT.
Na prova: DECLARE e CONSTANT
- A pseudocódigo nomeia um tipo com
DECLARE, e fixa um valor comCONSTANT.
DECLARE Age : INTEGER
Age ← 15
CONSTANT Pi ← 3.14
Common mistakes
- Give a variable a value before you use it.
- A constant is a value you do not change — name it clearly.
- Keep the right type: numbers for maths, strings for text.
Erros comuns
- Dê um valor a uma variável antes de usá-la.
- Uma constante é um valor que você não altera — nomeie-a claramente.
- Mantenha o tipo correto: números para matemática, strings para texto.
Now you try
- Make variables and do a little maths with them.
- Press Check answer to test your code.
Agora você tenta
- Crie variáveis e faça um pouco de matemática com elas.
- Clique em Check answer para testar seu código.
The variables width and · e height are set for you. Work out the rectangle's area · área (width × height) and store it in a variable called area. · As variáveis width e height estão definidas para você. Calcule a área do retângulo (largura × altura) e armazene-a em uma variável chamada area.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
price is a real number and quantity is an integer. Work out the total cost (price × quantity). · price é um número real e quantity é um inteiro. Calcule o custo total ⟨total⟩ (preço × quantidade).
Click Run to see the output here. · Clique em Executar para ver a saída aqui.
Read a whole number with input(), convert it with int(...), then print the number plus 3. For input 7, the output should be 10. · Leia um número inteiro com input(), converta-o com int(...), depois imprima o número mais 3. Para entrada 7, a saída deve ser 10.
Click Run to see the output here. · Clique em Executar para ver a saída aqui.