Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

kangwonlee/python-homework-081

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

75 Commits

Repository files navigation

Polynomial Evaluation 다항식 계산

  • Please work on exercise.py.
    exercise.py 파일을 수정하여 제출하세요.

Purpose 목적:

  • 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 가 다항식을 계산하는 방식을 흉내내봅시다.

Steps 단계:

  • Get n and validate
    n을 입력받고 검증
  • Collect coefficients in a list
    매개변수를 입력 받아 list 에 저장
  • Check if the highest order coefficient is zero
    가장 높은 차수의 계수가 0인지 확인
  • Get x from input
    x를 입력받음
  • Evaluate the polynomial
    다항식을 계산

Instructions 지침:

  • Take an int n from input function using the following prompt :
    int 값을 받아 변수 n에 저장하시오. 사용 프롬프트 :

    'maximum order of the polynomial in [2, 5] n = '
  • Print a string 문자열 출력 : '=========='

  • Print n using the following f string :
    n을 표시하시오. 사용 f 문자열 :

    f'n\t{n:8d}'
  • If n is smaller than 2 or larger than 5, print following error message and do not process further. Use if block for input validation.
    n이 2보다 작거나 5보다 크면 다음 오류 메시지를 표시하고 이후의 처리는 하지 마시오. if 로 해당 입력 검증 로직을 구현하시오.

    'Error : invalid n (2 <= n <= 5)'
  • Take n+1 int coefficients from input and store in a list. 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_coef using 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 int x from input using the following prompt :
    int 형 변수 x 를 입력 받으시오. 사용 프롬프트 :

    'x = '
  • Print a string 문자열 출력 : '=========='

  • Print the list containing polynomial coefficients using prefix :
    화면에 다항식의 계수를 담은 list를 표시하시오. 사용 안내 문자열 :

    'coefs :'
  • Print x using the following f string:
    x를 표시하시오. 사용 프롬프트 :

    f'x\t{x:8d}'
  • Print the evaluation result of the polynomial at x using 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'

Example Run 실행 예시:

n == 2

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

n == 4

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

Tips 팁:

  • Test your program with a small polynomial, like n=2 and 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!

Grading Criteria 채점 기준

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.

Submission 제출 방법

  1. Modify the contents of the exercise.py file to write your program.
    exercise.py 파일의 내용을 수정하여 프로그램을 작성합니다.
  2. Use the GitHub online editor to commit and push your changes. (See below for detailed instructions)
    GitHub 온라인 편집기를 사용하여 수정 사항을 커밋하고 푸시합니다. (자세한 사용법은 아래 참조)
  3. At the Actions tab of your Github repository, please check the result.
    깃헙 저장소의 Actions 탭에서 결과를 확인 바랍니다.

Shared Computer Warning
공용 컴퓨터 사용 시 주의사항

  • University labs: Always use incognito/private mode (Ctrl+Shift+N) to access GitHub. Closing the window automatically logs you out.
    대학 컴퓨터실: 반드시 시크릿 모드 (Ctrl+Shift+N)로 GitHub에 접속하세요. 창을 닫으면 자동으로 로그아웃됩니다.

How to Use the GitHub Online Editor
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.py file.
    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.
    줄 셋 의 [리포지토리로 이동] 선택하여 저장소로 복귀

Common Git Commands
주요 Git 명령어

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

Writing Descriptive Git Commit Messages
커밋 메시지 작성 권고안

  • 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.
    바람직한 커밋 메시지는 무엇을 변경했는지, 왜 변경했는지를 명확히 설명하여 나중에 수정 사항을 이해하기 쉽게 도와줄 것입니다.

Guidelines for Commit Messages
메시지 작성 지침

  • 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"는 너무 일반적입니다.

Examples 예시

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
모든 커밋은 파일을 변경함 — 아무 정보도 없음

Why It Matters
왜 중요한가

  • 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.
    커밋 히스토리는 코드가 어떻게 발전했는지 보여주는 기록입니다 — 읽기 쉽게 작성하세요.

Resources 참고 자료

NOTICE REGARDING STUDENT SUBMISSIONS
제출 결과물에 대한 알림

  • 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.
    위와 같은 목적으로 사용되기 원하지 않는 경우, 과제 마감일 전에 강사에게 알려주기 바랍니다.

Acknowledgments

  • 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.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

Contributors

Languages

AltStyle によって変換されたページ (->オリジナル) /