- Please work on
exercise.py.exercise.py파일을 수정하여 제출하세요.
- Using the user input, let's implement a program that will evalute a polynomial.
사용자 입력을 받아 들여 다항식을 계산하는 프로그램을 만들어 봅시다. - Let's try to mimic how some of the widely used numerical software such as MATLAB and Python's NumPy evaluate a polynomial.
널리 사용되는 연산 소프트웨어인 MATLAB 이나 Python의 NumPy 가 다항식을 계산하는 방식을 흉내내봅시다.
- Get
nand validaten을 입력받고 검증 - Collect coefficients in a list
매개변수를 입력 받아list에 저장 - Check if the highest order coefficient is zero
가장 높은 차수의 계수가 0인지 확인 - Get
xfrom inputx를 입력받음 - Evaluate the polynomial
다항식을 계산
-
Take an
intnfrom input function using the following prompt :int값을 받아 변수n에 저장하시오. 사용 프롬프트 :'maximum order of the polynomial in [2, 5] n = ' -
Print a string 문자열 출력 :
'==========' -
Print
nusing the following f string :n을 표시하시오. 사용 f 문자열 :f'n\t{n:8d}' -
If
nis smaller than 2 or larger than 5, print following error message and do not process further. Useifblock for input validation.n이 2보다 작거나 5보다 크면 다음 오류 메시지를 표시하고 이후의 처리는 하지 마시오.if로 해당 입력 검증 로직을 구현하시오.'Error : invalid n (2 <= n <= 5)' -
Take
n+1intcoefficients from input and store in alist. Order would be higher to lower. For example:n+1개의int계수를 입력으로부터 받아list로 저장하시오. 높은 차수 부터 낮은 차수의 순서로 저장하시오. 예를 들어 :$a_0 x^n + a_1 x^{n-1} + a_2 x^{n-2} + \cdots + a_{n-1}x + a_n$
will be stored as :
는 다음과 같이 저장될 것임 :[a_0, a_1, a_2, ... a_n_1, a_n]
Please use the following prompt :
사용 프롬프트 :f'coefficient a_{i} = ' -
Print a string 문자열 출력 :
'==========' -
Print the number of coefficient
n_coefusing the following f string :
화면에 계수의 갯수n_coef를 표시하시오. 사용 프롬프트 :f'n_coef\t{n_coef:8d}' -
Print the highest order coefficient (
$a_0$ ) using the following f string :
화면에 가장 높은 차수의 계수 ($a_0$ )를 표시하시오. 사용 f문자열 :f'a_0\t{a_0:8d}' -
If the highest order coefficient (
$a_0$ ) is zero, print the following error message and do not process further.
가장 높은 차수의 계수 ($a_0$ ) 가 0이면 다음 오류메시지를 표사하고 이후의 처리는 하지 마시오.'Error : a_0 is zero' -
Take an
intxfrom input using the following prompt :int형 변수x를 입력 받으시오. 사용 프롬프트 :'x = ' -
Print a string 문자열 출력 :
'==========' -
Print the
listcontaining polynomial coefficients using prefix :
화면에 다항식의 계수를 담은list를 표시하시오. 사용 안내 문자열 :'coefs :' -
Print
xusing the following f string:x를 표시하시오. 사용 프롬프트 :f'x\t{x:8d}' -
Print the evaluation result of the polynomial at
xusing the following prompt :x에서의 다항식 연산 결과를 표시하시오. 사용 프롬프트 :f'result\t{result:8d}' -
Do not use 다음 키워드는 사용 않기 바람 : 'while', 'try', 'except', 'def', 'return', and 'lambda'.
-
Please consider using these functions 다음 함수 사용을 생각해 보기 바랍니다 : 'print', 'input', 'int', 'range', 'len', and 'enumerate'
maximum order of the polynomial in [2, 5] n = 2
==========
n 2
coefficient a_0 = 1
coefficient a_1 = -6
coefficient a_2 = 9
==========
n_coef 3
a_0 1
x = 3
==========
coefs : [1, -6, 9]
x 3
result 0
maximum order of the polynomial in [2, 5] n = 4
==========
n 4
coefficient a_0 = 1
coefficient a_1 = 0
coefficient a_2 = 2
coefficient a_3 = 0
coefficient a_4 = 4
==========
n_coef 5
a_0 1
x = 2
==========
coefs : [1, 0, 2, 0, 4]
x 2
result 28
- Test your program with a small polynomial, like
n=2and coefficients[1, 0, 1](i.e.,$x^2 +1$ ), to ensure your evaluation is correct before trying larger polynomials.
프로그램 확인을 위해 작은 다항식을 활용하세요. 예를 들어n=2계수[1, 0, 1](즉,$x^2 +1$ ) 로 계산이 올바른지 확인한 후 더 큰 다항식을 시도하세요. - Assume that the input is valid. If invalid,
int()would raise an error and quit.
입력은 유효하다고 가정. 입력이 유효하지 않은 경우int()가 오류를 발생시키고 중단시킬 것임.
Happy coding!
| Criteria 기준 |
Points 배점 |
|---|---|
| Is the code written according to Python syntax? Python 문법대로 작성되었는가? |
2 |
| Does code respect style guidelines? 코드 스타일 권고사항을 준수하는가? |
1 |
| Is the result as expected? 결과가 예상과 같은가? |
2 |
From here is common to all assignments.
- Modify the contents of the
exercise.pyfile to write your program.exercise.py파일의 내용을 수정하여 프로그램을 작성합니다. - Use the GitHub online editor to commit and push your changes. (See below for detailed instructions)
GitHub 온라인 편집기를 사용하여 수정 사항을 커밋하고 푸시합니다. (자세한 사용법은 아래 참조) - At the Actions tab of your Github repository, please check the result.
깃헙 저장소의 Actions 탭에서 결과를 확인 바랍니다.
- University labs: Always use incognito/private mode (Ctrl+Shift+N) to access GitHub. Closing the window automatically logs you out.
대학 컴퓨터실: 반드시 시크릿 모드 (Ctrl+Shift+N)로 GitHub에 접속하세요. 창을 닫으면 자동으로 로그아웃됩니다.
- Press the . key while viewing the files in your repository on GitHub. This will launch a web version of VS Code.
저장소의 [Code] 탭을 선택 후 . 키를 누르면 MS VS Code 의 Web version 이 시작됨 - Make your changes to the
exercise.pyfile.exercise.py파일을 수정 - To commit your changes, click on the branch icon on the left sidebar (the third icon after the magnifying glass).
수정 사항을 commit 등록 하려면 왼쪽에서 줄 셋 아래 (확대경 다음) 세번째 가지치기 아이콘 선택 - Click the "+" sign next to the filename to stage your changes.
파일 이름의 오른쪽 + 기호 선택 (staging) - Write a brief description of your changes in the text box above.
위 빈칸에 변경 사항 설명 입력 - Click "Commit & Push."
[커밋 및 푸시] 선택 - Click "Back to Repository" on the branch icon to return to your repository.
줄 셋 의 [리포지토리로 이동] 선택하여 저장소로 복귀
If you work with Git from a terminal (e.g., VS Code terminal, WSL, or macOS Terminal), these are the commands you will use most often.
터미널(VS Code 터미널, WSL, macOS 터미널 등)에서 Git을 사용하는 경우, 가장 자주 사용하는 명령어입니다.
| Command | Description |
|---|---|
git status |
Show which files have been changed 변경된 파일 확인 |
git add <file> |
Stage a file for commit 커밋할 파일 준비 (스테이징) |
git commit -m "message" |
Save staged changes with a description 스테이징된 변경 사항을 메시지와 함께 저장 |
git push |
Send commits to GitHub 커밋을 GitHub에 전송 |
git log --oneline |
View commit history (one line per commit) 커밋 히스토리 조회 (한 줄씩) |
git diff |
See what changed before committing 커밋 전 변경 내용 확인 |
Typical workflow
일반적인 작업 흐름:
git add exercise.py
git commit -m "Add loop to calculate factorial"
git push- To help you develop better coding habits, we encourage descriptive Git commit messages when committing changes to your repository.
보다 바람직한 코딩 습관을 기르기 위해, 저장소에 변경 사항을 등록할 때 메시지에 보다 자세히 설명하는 것을 권합니다. - A good commit message clearly explains what you changed and why, making it easier for you to understand your work later.
바람직한 커밋 메시지는 무엇을 변경했는지, 왜 변경했는지를 명확히 설명하여 나중에 수정 사항을 이해하기 쉽게 도와줄 것입니다.
- Use the imperative mood — write as if giving an instruction: "Add", "Fix", "Update", "Refactor".
명령형으로 작성 — "Add", "Fix", "Update", "Refactor"와 같은 동사로 시작합니다. - Capitalize the first word and do not end with a period.
첫 글자는 대문자로 쓰고, 마침표는 붙이지 않습니다. - Keep it concise — aim for 15–50 characters, but ensure clarity.
간결하게 — 15–50자 정도로 작성하되, 명확성을 유지합니다. - Be specific — describe what changed and why, not just "update" or "fix".
구체적으로 — 무엇을 왜 변경했는지 설명합니다. 단순히 "update"나 "fix"는 너무 일반적입니다.
| Message | Why | |
|---|---|---|
| Good | Add factorial function to exercise.py |
Clearly states what was added 무엇을 추가했는지 명확히 설명 |
| Good | Fix off-by-one error in loop counter |
Identifies the bug and location 버그와 위치를 구체적으로 식별 |
| Good | Update print format to match expected output |
Explains purpose of the change 변경의 목적을 설명 |
| Bad | update |
Too vague — what was updated? 너무 모호 — 무엇을 수정했는지 알 수 없음 |
| Bad | fix 1 |
No context — fix what? 맥락 없음 — 무엇을 수정했는지 알 수 없음 |
| Bad | changed file |
Every commit changes a file — this says nothing 모든 커밋은 파일을 변경함 — 아무 정보도 없음 |
- Clear commit messages improve collaboration, debugging, and code review in real-world projects.
커밋 메시지가 명확하면 프로젝트 실무에서 공동 작업, 버그 수정, 코드 검토에서 도움을 얻을 수 있을 것입니다. - Your commit history tells the story of how your code evolved — make it readable.
커밋 히스토리는 코드가 어떻게 발전했는지 보여주는 기록입니다 — 읽기 쉽게 작성하세요.
-
Your submissions for this assignment may be used for various educational purposes. These purposes may include developing and improving educational tools, research, creating test cases, and training datasets.
제출 결과물은 다양한 교육 목적으로 사용될 수 있을 밝혀둡니다. (교육 도구 개발 및 개선, 연구, 테스트 케이스 및 교육용 데이터셋 생성 등). -
The submissions will be anonymized and used solely for educational or research purposes. No personally identifiable information will be shared.
제출된 결과물은 익명화되어 교육 및 연구 목적으로만 사용되며, 개인 식별 정보는 공유되지 않을 것입니다. -
If you do not wish to have your submission used for any of these purposes, please inform the instructor before the assignment deadline.
위와 같은 목적으로 사용되기 원하지 않는 경우, 과제 마감일 전에 강사에게 알려주기 바랍니다.
- The template for this assigment is registered as a part of #C-2025-016393 in the Korea Copyright Commission.
- Various LLMs and AI tools helped implement the templates for this assignment.
다양한 LLM 및 AI 도구가 이 과제의 템플릿 구현에 도움을 주었습니다.- Google Gemini
- xAI Grok3
- Claude.ai
- Perplexity Sonar
Until here is common to all assignments.