{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# 7일차\n", "5명이 한 팀이 되어 문제를 풀어 보자.\n", "\n", "# 함수\n", "\n", "# 문제 1\n", "다음 문제들의 답하시오. 팀의 각 사람이 한 문제씩 담당해보자.\n", "* 함수의 개념 설명하기\n", "* 함수를 작성하는 방법과 호출하는 방법, 예제 코드를 작성해보자.\n", "* 결과가 있는 함수와 결과가 없는 함수의 차이? 예제 코드를 작성해보자.\n", "* 함수 안에서 함수를 호출 할 수 있는가? 몇 번이나 호출 할 수 있을까?\n", "* 함수의 인자로 함수를 쓸 수 있는가? " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 문제 2\n", "다음 코드의 실행 결과를 예상해보고, 실행 결과와 비교해보자" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#1\n", "def one(val):\n", " return input(\"\\rthis is one \")+ val\n", "\n", "def two():\n", " return input(\"\\rthis is two \")\n", "\n", "\n", "print(one(two()))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#2\n", "def hi(name):\n", " print(\"hi, nice to meet you \", name)\n", " \n", "hi(\"Tasha\")\n", "hl(\"Annie\")\n", "hI(\"Jennie\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#3\n", "def sum(numbers):\n", " total = 0\n", " for x in numbers:\n", " total += x\n", "\n", " return total\n", "\n", "print(sum((8, 2, 3, 0, 7)))" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "#4\n", "def unique_list(l): \n", " x = [] \n", " for a in l: \n", " if a not in x: \n", " x.append(a) \n", "\n", " return x \n", "\n", "print(unique_list([1,2,3,3,3,3,4,5])) " ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 문제 3\n", "어떤 숫자가 범위 내에 있는 숫자인지 확인하는 프로그램을 순서도와 함께 작성해보자. 단, ```if, else, while, def``` 등을 사용하자 " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code here\n", "yourtext = input(\"your guess? \")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 문제 4\n", "다음의 문제를 해결해보자.\n", "* ```circle(X), rectangle(X), triangle(X)```함수를 작성해서 원, 사각형, 삼각형을 그려보자. X 길이만큼 도형을 그리도록 하자.\n", "* 위의 도형을 그리는 함수를 일반화하여 ```polygon(X, edge)```이라는 함수를 만들어보자. 이때 ```edge```는 꼭지점의 수를 나타낸다.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# your code here" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 문제 5\n", "사용자가 입력한 숫자가 소수인지 판단하는 프로그램을 작성해보자. 소수이면 True를 아니면 False를 출력하도록하자. 힌트는 나머지 연산자 (%)" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "나머지: 3\n" ] } ], "source": [ "# 나머지 연산의 예\n", "result = 13 % 5;\n", "print (\"나머지: \", result);" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# 숙제\n", "입력된 두 수 중 큰 수를 출력하는 `Larger(A, B)`라는 프로그램을 작성해보자. 또한 이 함수를 활용하여 입력 받은 세 개의 수 중 가장 큰 수를 찾아보자." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.5" } }, "nbformat": 4, "nbformat_minor": 2 }