Numbers & operators · 숫자 및 연산자
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.
두 종류의 숫자
- 정수(integer,
int)는 소수점 없는 전체 숫자입니다. 예:7또는-3. - 부동소수점(float)은 소수점이 있는 숫자입니다. 예:
2.5. /을 이용한 나눗셈은 항상 부동소수점을 반환하며, 예:4 / 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.
더하기, 빼기, 곱하기, 나누기
+은 더하기,-은 빼기,*은 곱하기,/은 나누기입니다.- 변수나 단순 숫자와 함께 사용할 수 있습니다.
- 연산자 양쪽에 공백을 두지는 않아도 되지만, 코드를 읽기 쉽게 하는 데 도움이 됩니다.
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.
정수 나눗셈, 나머지, 지수
//은 나눈 후 정수 부분만 남깁니다(地板除法).%은 나머지를 반환합니다(모듈로라고도 함).**은 제곱: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.
연산 순서
- Python은 먼저
**을 처리하고, 이어서*///%를, 마지막으로+-를 수행합니다. - 이는 수학에서 사용하는 순서와 같습니다.
- 순서를 바꾸려면 괄호
(...)을 사용하세요.
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.
흔한 실수
/은 항상 부동소수점을 반환합니다(예:4 / 2은2.0임). 정수가 필요하면//을 사용하세요.- 제연산은
**이지,^이 아닙니다. "3" + "4"은 텍스트를"34"로 결합합니다. 숫자7에 더하는 것이 아닙니다.
Now you try
- Store each answer in the variable named in the task.
- Press Check answer to test your code.
이제 직접 해보기
- 각 답을 작업에서 지정한 변수에 저장하세요.
- Answer 확인 버튼을 눌러 코드를 테스트하세요.
Order of operations · 연산 우선순위
Python evaluates × and ÷ before + and −, left to right. · Python은 ×와 ÷를 +와 −보다 먼저 계산하며, 왼쪽에서 오른쪽으로 진행합니다.
Set length to 8 and width to 5. Then store their product in a variable called area. · length를 8로, width를 5로 설정하십시오. 그다음 их 곱을 area라는 변수에 저장하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
You share 17 sweets among 5 children. Store how many each child gets in each (use //), and how many are left over in left (use %). · 17개의 사탕을 5명의 아이들에게 나누어 줍니다. 각자 receiving하는 개수를 each에 저장하고(// 사용), 남아있는 개수를 left에 저장하십시오(% 사용).
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
Store 3 ** 2 + 1 in result. Then use parentheses to store (3 + 1) ** 2 in grouped. · 3 ** 2 + 1를 result에 저장하십시오. 그다음 괄호를 사용하여 (3 + 1) ** 2를 grouped에 저장하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.
celsius is 37. Store the temperature in Fahrenheit in fahrenheit, using the formula celsius × 9 ÷ 5 + 32. · celsius는 37입니다. celsius × 9 ÷ 5 + 32 공식을 사용하여 페렌하이트 온도를 fahrenheit에 저장하십시오.
Click Run to see the output here. · 출력을 보려면 '실행'을 클릭하세요.