[Python] 코드아카데미 따라하기 - chapter.1 Syntax

in #python8 years ago

안녕하세요? 파이썬을 이제 막 배우고 있는 사람입니다.
파이썬을 쉽게 학습하는 데 코드아카데미가 좋은 것 같아 제가 학습한 걸 공유할 겸 올리고 있습니다.
혹시 코드아카데미를 모르시는 분들은 코드아카데미에 방문하셔서 회원가입을 해주세요.
가입하는데 전혀 어렵지 않습니다. 그러면 지금부터 파이썬 따라하기를 시작하겠습니다. 이 게시글은 코드아카데미를 100% 참고했습니다. 혹시 영어 울렁증이 있어서 공부하기 힘드셨던 분들은 영문과 번역을 함께 올렸기 때문에 공부하시는데 조금이나마 수월하실겁니다.

1. Welcome!

Python is an easy to learn programming language. You can use it to create web apps, games, even a search engine!
(반갑습니다. 파이썬은 배우기 쉬운 프로그래밍 언어입니다. 당신은 웹 어플리케이션, 게임 심지어 검색 엔진을 만드는데 파이썬을 사용할 수 있습니다.)
Ready to learn Python? Click Save & Submit Code to continue!
(파이썬 학습 준비 되셨나요? 그럼 Save&Submit Code 버튼을 누르세요.)

*Save&Submit Code 버튼을 클릭하시거나 ctrl+enter키를 누르셔도 됩니다.

2. Variables

(변수)
Creating web apps, games, and search engines all involve storing and working with different types of data.
(웹 어플리케이션, 게임 그리고 검색 엔진을 만드는 모든 것은 서로 다른 타입의 데이터를 저장하고 운용하는 것을 수반한다.)
They do so using variables. A variable stores a piece of data, and gives it a specific name.
(이러한 것을 만드는 데 변수가 사용된다. 변수는 데이터 조각을 저장하고 특정 이름을 부여한다.)

For example:
spam = 5

The variable spam now stores the number 5.
(spam이라는 변수는 숫자 5를 저장하고 있다.)

Instructions

  1. Set the variable my_variable equal to the value 10.
    (my_variable라는 변수에 변수값 10을 부여한다.)
  2. Click the Save & Submit button to run your code.
    (코드 실행을 위해 Save&Submit 버튼을 클릭하세요.)

3. Booleans - 불리언(불 연산자)

Great! You just stored a number in a variable.
(잘하셨습니다. 당신은 변수 안에 숫자를 막 저장했습니다.)
Numbers are one data type we use in programming. A second data type is called a boolean.
(숫자는 프로그래밍에서 우리가 사용하는 하나의 데이터 타입입니다. 두번째 데이터 타입은 불리언이라 불리는 것입니다.)
A boolean is like a light switch. It can only have two values. Just like a light switch can only be on or off, a boolean can only be True or False.
(불리언은 전등 스위치와 같습니다. 불리언은 오직 두 개의 값만 가지고 있습니다. 전등 스위치는 오직 켜지거나 꺼지는 거만 있듯이, 불리언은 오직 진실이거나 거짓입니다.)
You can use variables to store booleans like this:
(당신은 이와 같이 불리언을 저장하기 위해 변수를 사용할 수 있습니다.)
a = True
b = False

Instructions

Set the following variables to the corresponding values:
(이에 해당하는 다음의 변수를 부여하세요.)

  1. my_int to the value 7
  2. my_float to the value 1.23
  3. my_bool to the value True

4. You've Been Reassigned

Now you know how to use variables to store values.
(현재 당신은 값을 저장하기 위해 변수를 어떻게 사용하는지 알게됐습니다.)

Say my_int = 7.

You can change the value of a variable by "reassigning" it, like this:
(당신은 이와 같이 변수 값을 재할당하여 바꿀 수 있습니다.

my_int = 3

Instructions

Try it and see! Change the value of my_int from 7 to 3 in the editor.
(시도하고 보세요! 에디터에서 my_int 값을 7에서 3으로 바꿔보세요.)

5. Whitespace

In Python, whitespace is used to structure code.
(파이썬에서, 화이트스페이스는 스트럭쳐 코드로 사용됩니다.)
*스트럭쳐 코드는 말 그대로 구조코드로써 구문을 구별해주는 기능을 합니다.
Whitespace is important, so you have to be careful with how you use it.
(화이트스페이스는 중요합니다 그러므로 당신은 화이트스페이스를 어떤식으로 사용하는지에 대해 주의를 기울여야합니다.)

Instructions

The code on the right is badly formatted. Hit "Save & Submit Code" to see what happens.
(오른쪽의 코드는 잘못된 형식입니다. Save&Submit Code 버튼을 눌러서 어떤 일이 생기는지 보세요.)
You should see an error message. We'll fix it in the next exercise!
(에러 메시지가 보일겁니다. 다음 장에 이 코드를 고칠 것입니다.)

6. Whitespace Means Right Space

Now let's examine the error from the last lesson:
(이전 레슨에서 이 에러를 검토해봅시다.)

IndentationError: expected an indented block

You'll get this error whenever your whitespace is off.
(화이트스페이스가 없을 때마다 위와 같은 에러가 발생할 것입니다.)

Instructions

Properly indent the code with four spaces before eggs on line 2 and another four before return on line 3.
(라인 2의 eggs 이전과 라인 3을 반환하기 전에도 4번의 스페이스로 코드를 적절히 들여쓰기 한다.)
You should indent your code with four spaces.
(당신은 4번의 스페이스로 코드를 들여쓰기 해야한다.)
*스페이스바를 4번 눌러도 되고 Caps Lock키를 한번 눌러도 된다.

7. A Matter of Interpretation

The window in the top right corner of the page is called the interpreter.
(이 페이지의 위에서 오른쪽에 있는 창은 인터프리터라고 불립니다.)
The interpreter runs your code line by line, and checks for any errors.
(인터프리터는 한줄씩 당신의 코드를 실행하고 어떤 에러를 검사해줍니다.)
cats = 3

In the above example, we create a variable cats and assign it the value of 3.
(위의 예제에서 cats라는 변수를 만들었고 값 3을 할당했습니다.)

Instructions

  1. Create a variable called spam and assign it the value of True.
    (spam이라는 변수를 만들고 True 값을 할당해주세요.)
  2. Create a variable called eggs and assign it the value of False.
    (eggs라는 변수를 만들고 False 값을 할당해주세요.)

8. Single Line Comments

You probably saw us use the # sign a few times in earlier exercises.
(당신은 지난 장에서 몇 번정도 # 표시를 사용한 걸 본 적 있을 것입니다.)
The #sign is for comments.
(# 표시는 코멘트를 위한 것입니다.)
A comment is a line of text that Python won't try to run as code.
(코멘트는 파이썬이 코드로써 실행하려고 하지 않는 텍스트 라인입니다.)
It's just for humans to read.
(단지 사람이 읽기 위한 것입니다.)
Comments make your program easier to understand.
(코멘트는 당신의 프로그램을 더 이해하기 쉽게 합니다.)
When you look back at your code or others want to collaborate with you, they can read your comments and easily figure out what your code does.
(당신의 코드를 다시 보거나 다른사람이 당신과 협엄할 때 그들은 당신의 코멘트를 읽고 당신의 코드가 무얼하는지 파악할 수 있습니다.)

Instructions

Write a comment on line 1. Make sure it starts with #. It can say anything you like.
(첫번째 라인에 코멘트를 써보세요. #로 시작해야합니다. 아무거나 쓰면 됩니다.)

9. Multi-Line Comments

The # sign will only comment out a single line.
(# 표시는 오직 한 라인만 코멘트 처리합니다.)
While you could write a multi-line comment, starting each line with #, that can be a pain.
(각 라인을 #로 시작하여 여러줄의 코멘트를 쓸 수 있지만, 이건 고통이 될 수 있습니다.)
Instead, for multi-line comments, you can include the whole block in a set of triple quotation marks:
(대신에 여러줄의 코멘트를 " 마크 세 개로 전체 블록을 포함할 수 있습니다.)
"""Sipping from your cup 'til it runneth over, Holy Grail. """

Instructions

Write a multi-line comment in the editor. It can be any text you'd like!
(에디터에 다중라인 코멘트를 써보세요. 원하는 어떠한 글자라도 가능합니다.)

10. Math

Great! Now let's do some math.
(잘하셨습니다. 그럼 지금부터 수학을 해봅시다.)
You can add, subtract, multiply, divide numbers like this
(당신은 이와 같이 숫자를 더하고, 빼고, 곱하고, 나눌 수 있습니다.)
addition = 72 + 23
subtraction = 108 - 204
multiplication = 108 * 0.5
division = 108 / 9

Instructions

Set the variable count_to equal to the sum of two big numbers.
(count_to라는 변수가 두 개의 큰 숫자의 합과 같도록 배치해주세요.)

11. Exponentiation

All that math can be done on a calculator, so why use Python?
(모든 수학은 계산기로 가능합니다 그런데 왜 파이선을 사용할까요?)
Because you can combine math with other data types (e.g. booleans) and commands to create useful programs.
(왜냐면 유용한 프로그램을 만들기 위한 다른 데이터 타입과 명령어를 수학과 결합할 수 있기 때문입니다.)
Calculators just stick to numbers.
(계산기는 단지 숫자에만 충실합니다.)
Now let's work with exponents.
(지금부터 지수를 사용해봅시다.)
eight = 2 ** 3

In the above example, we create a new variable called eight and set it to 8, or the result of 2 to the power to 3 (2^3).
(위의 예제는 eight이라는 변수에 8 또는 2의 3제곱의 결과값을 할당한 것입니다.)
Notice that we use ** instead of * or the multiplication operator.
(* 또는 곱하기 연산자 대신에 ** 사용한 것을 알 수 있습니다.)

Instructions

Create a new variable called eggs and use exponents to set eggs equal 100.
(eggs라는 새로운 변수를 만들고 지수를 사용하여 100이 되도록 해보세요.)
Try raising 10 to the power of 2.
(10의 2제곱이 되도록 해보세요.)

12. Modulo

Our final operator is modulo.
(우리의 마지막 연산자는 모듈로입니다.)
Modulo returns the remainder from a division.
(모듈로는 나누기의 나머지값을 반환합니다.)
So, if you type 3 % 2, it will return 1, because 2 goes into 3 evenly once, with 1 left over.
(그러므로, 만약 3%2라면 1을 반환합니다. 왜냐면 3은 2로 나머지 1을 포함하여 균등히(나머지 없이) 나누어질 수 있기 때문입니다.)

Instructions

Use modulo to set spam equal to 1.
(모듈로를 사용하여 spam 변수가 1이 되도록 하세요.)
You can use any two numbers that will leave a remainder of 1 to do this.
(이걸 하기 위해서는 어떤 두 개의 숫자를 사용하여 나머지 1이 남도록하세요.)

13. Bringing It All Together

Nice work! So far, you've learned about:
(잘하셨어요! 이제까지 이와같은 것에 대해 배웠습니다.)
Variables, which store values for later use
(값을 저장하고 나중에 사용하는, 변수)
Data types, such as numbers and booleans
(숫자나 불리언과 같은, 데이타 타입)
Whitespace, which separates statements
(구간을 나누는 화이트스페이스)
Comments, which make your code easier to read
(당신의 코드를 더 쉽게 읽도록 하는, 코멘트)
Arithmetic operations, including+, -, , /, , and %
(+,-,
,/,
그리고 %를 포함한 산술 연산자)

Instructions

Let's put our knowledge to work.
(우리의 지식을 활용해봅시다.)
Write a single-line comment on line 1. It can be anything! (Make sure it starts with #)
(첫번째 줄에는 싱글라인 코멘트를 써봅시다. 아무거나 상관없습니다. #로 시작만해주세요.)
Set the variable monty equal to True.
(monty 변수에 True를 넣어봅시다.)
Set another variable python equal to 1.234.
(Python 변수가 1.234와 같도록 해봅시다.)
Set a third variable monty_python equal to python squared.
(monty_python 변수가 python의 2제곱이 되도록 해봅시다.)

다음 강좌는 Tip Calculator 입니다.

Coin Marketplace

STEEM 0.27
TRX 0.11
JST 0.030
BTC 69245.03
ETH 3778.28
USDT 1.00
SBD 3.51