[빛-Hikari-의 Python] 01장-03 Python 정보 (PyCharm을 사용하여 프로그램을 작성하고 실행)
5635 단어 IT 교육파이썬기본 정보 기술자 시험프로그래밍 초보자
【01-03】PyCharm에 프로그램을 써 실행한다
지금까지 프로그램은 콘솔에서 실행되어 왔습니다.
이번에는 프로그램을 텍스트 편집기에 쓰고 실행 결과를 콘솔에서 쓰는 방법을 살펴 보겠습니다.
PyCharm에서 프로그램 실행 및 인터프리터 설정
이전 「01-02」 에서 설명한 대로, 프로그램은 이하의 방법으로 실행할 수가 있습니다.
이번에는, 그 후자인 「프로그램을 써 실행하는 방법」에 대해 설명해 가고 싶습니다.
우선, 전회에서도 설명했습니다만, PyCharm을 기동하면 이하의 화면이 나옵니다.

직접 데스크탑에 작성한 프로젝트 파일의 프로젝트 이름 [python]을 마우스 오른쪽 버튼으로 클릭하고 [New] → [Directory]를 선택합니다.

그리고 거기에 폴더를 만듭니다. 이번에는 chap01입니다.

[chap01]의 위치를 마우스 오른쪽 버튼으로 클릭하고 [New] → [Python File]을 선택합니다.

프로그램 파일 이름을 여기에 지정합니다. 이번에는 설명을 위해 01-03입니다.

아래의 빨간색 테두리에 프로그램을 작성합니다.

다음 프로그램을 입력하십시오. (자세한 설명은 나중에 설명합니다.)
01-03.py
a = 15
b = 10
print(a+b)
프로그램을 쓰면 실행을 합니다만, 실행시에는 인터프리터를 지정할 필요가 있습니다. (첫회만)
다음과 같은 오류가 발생한 것 같습니다.

이것은 인터프리터를 지정하지 않기 때문에, 이대로는 프로그램을 실행할 수 없는 상태입니다.
인터프리터는 프로그래밍 언어로 작성한 코드를 수시로 해석하면서 실행하는 프로그램입니다.
인터프리터 지정 【첫회만】
인터프리터를 지정하는 방법을 설명합니다.
다음 위치 [Add Interpreter]를 클릭하여 인터프리터를 설정합니다.

아래의 확인을 클릭합니다.

인터프리터가 다운로드되고 설치됩니다.

원래 프로그램 편집 화면으로 돌아갑니다. 이하의 빨간색 프레임의 개소는 1분 정도 하면 자동으로 사라집니다.


이제 인터프리터를 설치할 수 있습니다.
프로그램 실행
아래의 순서로 [01-03]을 마우스 오른쪽 버튼으로 클릭 → [Run '01-03']을 선택하면 실행됩니다.

그러면 다음 위치에 실행 결과가 표시됩니다.

이제 파일에서 실행할 수 있습니다.
PyCharm에서 콘솔을 사용하는 방법
[01-02]에서 콘솔에서 명령처럼 프로그램을 작성하고 실행했습니다.
PyCharm에서도 마찬가지입니다.
다음과 같이 [Tools] → [Python or Debug Console]을 선택합니다.

콘솔 화면이 나오는 것을 확인할 수 있습니다.

아래의 ">>>"프롬프트의 위치에,
print(3+4)
를 입력하고 Enter를 누르면 실행됩니다.

위의 방법으로도 콘솔에서 실행할 수 있는지 확인할 수 있었습니까?
마지막으로
이와 같이 Pycharm에 기재하고 나서 실행 화면에서 결과를 확인하는 방법도 있습니다.
이제 두 가지 방법을 배웠지만 실제로는 두 가지 방법을 모두 사용합니다. 여기 절은 기본적인 부분이므로 꼭 누르십시오.
다음에 제2장부터는 실제 프로그램의 내용에 들어가고 싶습니다.
【목차 링크】로 돌아온다
Reference
이 문제에 관하여([빛-Hikari-의 Python] 01장-03 Python 정보 (PyCharm을 사용하여 프로그램을 작성하고 실행)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ko0821/items/59a48e307c153c615aa4텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)