Variables, constants & data types · 변수, 상수 및 데이터 타입
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.
변수는 이름이 붙은 상자입니다
- 변수(variable) 는 값을 저장하는 이름입니다.
=으로 값을 넣는데,これを **대입(assignment)**이라고 합니다.- 명확한 이름을 사용하여 프로그램이 쉽게 읽히게 하세요.
age = 15
price = 2.50
name = "Ada"
print(age, price, name)
Variables as named boxes · 이름이 붙은 상자로서의 변수
Each = puts a value into a named box you can use later. · 각 =은 나중에 사용할 수 있는 이름이 붙은 상자에 값을 넣습니다.
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.
다섯 가지 데이터 유형
- IGCSE는 다섯 가지 기본 **데이터 유형(data types)**을 사용합니다:
- 정수(integer) → Python
int; 실수(real) →float. - 문자(char), 문자열(string) →
str; 부울리안(Boolean) →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.
상수는 변하지 않습니다
- **상수(constant)**는 프로그램 실행 중 변경되지 않는 값입니다.
- Python에는 특수 키워드가 없으므로, 상수는 대문자로 표기합니다:
CAPITALS. - 다른 독자에게 경고합니다: 나를 변경하지 마십시오.
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.
유형 간 변환
input()은 문자열을 제공하므로, 숫자가 필요할 때 변환해야 합니다.int(x)은 정수를 만들며,float(x)은 부동소수점을,str(x)은 텍스트를 만듭니다.
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.
시험: DECLARE와 CONSTANT
- 가짜코드는 type을
DECLARE으로 명시하고, value를CONSTANT으로 고정합니다.
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.
흔한 실수
- 변수를 사용할 전에 값을 부여해야 합니다.
- 상수는 변경하지 않는 값이며, 명확한 이름을 부여하세요.
- 올바른 유형을 유지하세요: 수학용은 숫자, 텍스트용은 문자열.
Now you try
- Make variables and do a little maths with them.
- Press Check answer to test your code.
이제 직접 해보기
- 변수를 만들고 약간의 수학을 해보세요.
- Answer 확인 버튼을 눌러 코드를 테스트하세요.
The variables width and height are set for you. Work out the rectangle's area (width × height) and store it in a variable called area. · 변수 width과 height이 주어졌습니다. 직사각형의 면적(너비 × 높이)를 구하여 area이라는 변수에 저장하세요.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
price is a real number and quantity is an integer. Work out the total cost (price × quantity). · price은 실수이고 quantity은 정수입니다. total 비용(가격 × 수량)을 구하세요.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Read a whole number with input(), convert it with int(...), then print the number plus 3. For input 7, the output should be 10. · input()으로 정수를 읽고, int(...)으로 변환한 후 number 3을 더한 값을 출력하세요. 입력 7에 대해 출력은 10이어야 합니다.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.