Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 문제1번\n",
- "- •a=\"Hello Python\" 문자열을 Slicing과 연결 연산자 (+)를 사용하여 \"Python Hello\"로 변경하시오.\n",
- "- ◾[주의] a 변수 자체에 \"Python Hello\" 문자열이 저장되어야 함\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 43,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Python Hello\n"
- ]
- }
- ],
- "source": [
- "a = \"Hello Python\"\n",
- "a = a[6:] + \" \" + a[0:5]\n",
- "print(a)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "슬라이싱과 + 연산을 이용하여 문자열을 변경하였다."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 문제2번\n",
- "- •b=\"Hello Python World\" 문자열을 Slicing과 연결 연산자 (+)를 사용하여 \"World Python Hello\"로 변경하시오.\n",
- "- ◾[주의] b 변수 자체에 \"Python Hello\" 문자열이 저장되어야 함 \n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 44,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "World Python Hello\n",
- "Python Hello\n"
- ]
- }
- ],
- "source": [
- "b = \"Hello Python World\"\n",
- "str = b[6:12]\n",
- "str1 = ' '+b[0:5]\n",
- "str2 = b[13:] + ' '\n",
- "b = str + str1\n",
- "print ( str2+b)\n",
- "print (b)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "슬라이싱과 + 연산자를 사용하여 문자열을 수정하였다 하지만 b변수 자체에 world python hello가 들어가야하는것 같은데 오타인거 같았다"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 문제3번\n",
- "- •c=\"Hello\"를 \"olleH\"로 변경하시오\n",
- "- ◾[주의] c 변수 자체에 \"olleH\" 문자열이 저장되어야 함\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 41,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "olleH\n"
- ]
- }
- ],
- "source": [
- "c = \"Hello\"\n",
- "c = c[::-1]\n",
- "print(c)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "스텝을 -1 나머지값들을 디폴트로 하면 문자열이 뒤집힌다."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 문제4번\n",
- "\n",
- "- •s=\"python\"에 대해 다음 문제를 풀어보시오.\n",
- "- 1.s[0], s[0][0], s[0][0][0]은 각각 어떤 값이 나오는지 확인하고 그 이유를 나름대로 설명해 보시오.\n",
- "- 2.s[-100], s[100]은 값이 나오는지 에러가 나오는지 확인하고 그 결과에 대한 이유를 나름대로 설명해 보시오.\n",
- "- 3.s[-100, 100]은 값이 나오는지 에러가 나오는지 확인하고 그 결과에 대한 이유를 나름대로 설명해 보시오.\n",
- "- 4.s[1:-1]의 결과를 확인하고 그 결과에 대한 이유를 정확하게 설명하시오.\n",
- "- 5.s[3:-3]의 결과를 확인하고 그 결과에 대한 이유를 정확하게 설명하시오.\n",
- "\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 30,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "p p p\n",
- "\n"
- ]
- }
- ],
- "source": [
- "s = \"python\"\n",
- "print(s[0],s[0][0], s[0][0][0])\n",
- "print(s[3:-3])"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "1. s[0],s[0][0], s[0][0][0]는 모두 p가 출력된다. \n",
- "2. s[-100], s[100]는 string index out of range라는 표시와 함께 오류가뜬다 이유는 s라는 문자열에 인덱스를 넘어가서 라고 생각한다.\n",
- "3. s[-100, 100] 는 string indices must be integer 오류가 나타난다\n",
- "4. s[1:-1]는 1번 인덱스부터 -1인덱스(포함하지않음) 까지이므로 ytho가 출력된다\n",
- "5. s[3:-3]는 3번 인덱스부터 -3번째(포함하지않음) 까지이므로 h(포함)부터 h(포함x) 범위이다 따라서 아무것도 출력되지않는다.\n",
- "- 1,3번의 경우 인덱싱과 슬라이싱에 대해서 알지만 마치 2차원이상의 배열처럼 인덱스가 주어진 문자열에 대해서는 수업 때 집중을 못한것인지는 모르겠지만 어떻게 작용하는지 모르겠다"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 문제5번\n",
- "- •for문을 활용하여 1부터 100사이의 홀수를 출력하시오.\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 34,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99 "
- ]
- }
- ],
- "source": [
- "for i in range (100):\n",
- " if ( i % 2 == 1 ):\n",
- " print (i, end=' ')"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "만약에 0부터 99까지 2로 나누어 떨어지지 않는다면 소수이므로 출력한다."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 문제6번\n",
- "- •while문을 활용하여 1부터 100사이의 짝수의 합을 계산하여 출력하시오."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 1,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "2550\n"
- ]
- }
- ],
- "source": [
- "i = 0\n",
- "sum = 0\n",
- "while ( i <= 100):\n",
- " if ( i % 2 == 0):\n",
- " sum += i\n",
- " i+=1\n",
- "print(sum)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "0부터 100까지 만약 i가 2로 나누어떨어진다면 sum += i를 수행한뒤 i+=1이 수행된다"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 문제7번\n",
- "- •사용자로 부터 임의의 정수를 입력받고, 해당 숫자를 역순으로 출력하는 프로그램을 작성하시오\n",
- "- [실행 예]\n",
- "- 정수를 입력하세요: 3125\n",
- "- 숫자 역순은 5213 입니다.\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 36,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "3125\n",
- "5213\n"
- ]
- }
- ],
- "source": [
- "num = input()\n",
- "print(num[::-1])"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "정수를 문자열의 형태로 입력받는다.\n",
- "슬라이싱의 스텝을 -1로 주고 나머지를 디폴트로하여 역순으로 출력한다"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### 문제8번\n",
- "- •사용자로 부터 정수를 입력받아서 1부터 그 사이에 존재하는 소수 (Prime number)를 출력하는 파이썬 프로그램을 작성하시오\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 37,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "16\n",
- "prime : 2\n",
- "prime : 3\n",
- "prime : 5\n",
- "prime : 7\n",
- "prime : 11\n",
- "prime : 13\n"
- ]
- }
- ],
- "source": [
- "def is_prime(num):\n",
- " i = 1\n",
- " count = 0\n",
- " while( i <= num):\n",
- " if ( num % i == 0):\n",
- " count+=1\n",
- " i+=1\n",
- " if ( count == 2):\n",
- " return 1\n",
- " else:\n",
- " return 0\n",
- "num = int(input())\n",
- "i = 0\n",
- "while ( i <= num ):\n",
- " if ( is_prime(i) == 1 ):\n",
- " print(\"prime : \" , i)\n",
- " i+=1\n",
- "\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "is_prime 함수는 임의의 매개변수를 받아 소수라면1 아니라면 0을 판단하여 반환한다.\n",
- "반복문에서 입력받은 임의의 정수까지 is_prime(i)를 통해 1이 반환된다면 출력한다."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "### ACM-ICPC 문제 2439번\n",
- "- 별찍기-2\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 38,
- "metadata": {
- "scrolled": false
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "5\n",
- " *\n",
- " **\n",
- " ***\n",
- " ****\n",
- "*****"
- ]
- }
- ],
- "source": [
- "ch = ' '\n",
- "ch2 = '*'\n",
- "num = int( input() );\n",
- "for i in range(num):\n",
- " if ( i>0):\n",
- " print ()\n",
- " for j in range(num-(i+1)):\n",
- " print (ch,end='')\n",
- " for k in range(num - (num-(i+1))):\n",
- " print (ch2, end='')\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "공백과 * 문자 두개를 ch에 저장한다.\n",
- "사용자로부터 임의의 num을 입력받아 반복문을 실행한다.\n",
- "이중반복문안의 반복문 2개를 삽입하여 적절히 인덱스의 개수를 조절하여 출력할 수 있다."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### ACM-ICPC 문제 1924번\n",
- "- 2007년"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 45,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "4 7\n",
- "SAT\n"
- ]
- }
- ],
- "source": [
- "a, b = input().split()\n",
- "month = int(a)\n",
- "day = int(b)\n",
- "list_date = [ 'MON','TUE','WED','THU','FRI','SAT','SUN']\n",
- "if ( month == 1 or month == 10 ):\n",
- " if (day % 7 == 1):\n",
- " print (list_date[0])\n",
- " if (day % 7 == 2):\n",
- " print (list_date[1])\n",
- " if (day % 7 == 3):\n",
- " print (list_date[2])\n",
- " if (day % 7 == 4):\n",
- " print (list_date[3])\n",
- " if (day % 7 == 5):\n",
- " print (list_date[4])\n",
- " if (day % 7 == 6):\n",
- " print (list_date[5])\n",
- " if (day % 7 == 0):\n",
- " print (list_date[6])\n",
- " \n",
- "if ( month == 5 ):\n",
- " if (day % 7 == 1):\n",
- " print (list_date[1])\n",
- " if (day % 7 == 2):\n",
- " print (list_date[2])\n",
- " if (day % 7 == 3):\n",
- " print (list_date[3])\n",
- " if (day % 7 == 4):\n",
- " print (list_date[4])\n",
- " if (day % 7 == 5):\n",
- " print (list_date[5])\n",
- " if (day % 7 == 6):\n",
- " print (list_date[6])\n",
- " if (day % 7 == 0):\n",
- " print (list_date[0])\n",
- "if ( month == 8 ):\n",
- " if (day % 7 == 1):\n",
- " print (list_date[2])\n",
- " if (day % 7 == 2):\n",
- " print (list_date[3])\n",
- " if (day % 7 == 3):\n",
- " print (list_date[4])\n",
- " if (day % 7 == 4):\n",
- " print (list_date[5])\n",
- " if (day % 7 == 5):\n",
- " print (list_date[6])\n",
- " if (day % 7 == 6):\n",
- " print (list_date[0])\n",
- " if (day % 7 == 0):\n",
- " print (list_date[1])\n",
- "if ( month == 2 or month == 3 or month == 11 ):\n",
- " if (day % 7 == 1):\n",
- " print (list_date[3])\n",
- " if (day % 7 == 2):\n",
- " print (list_date[4])\n",
- " if (day % 7 == 3):\n",
- " print (list_date[5])\n",
- " if (day % 7 == 4):\n",
- " print (list_date[6])\n",
- " if (day % 7 == 5):\n",
- " print (list_date[0])\n",
- " if (day % 7 == 6):\n",
- " print (list_date[1])\n",
- " if (day % 7 == 0):\n",
- " print (list_date[2])\n",
- "if ( month == 6 ):\n",
- " if (day % 7 == 1):\n",
- " print (list_date[4])\n",
- " if (day % 7 == 2):\n",
- " print (list_date[5])\n",
- " if (day % 7 == 3):\n",
- " print (list_date[6])\n",
- " if (day % 7 == 4):\n",
- " print (list_date[0])\n",
- " if (day % 7 == 5):\n",
- " print (list_date[1])\n",
- " if (day % 7 == 6):\n",
- " print (list_date[2])\n",
- " if (day % 7 == 0):\n",
- " print (list_date[3])\n",
- "if ( month == 9 or month == 12 ):\n",
- " if (day % 7 == 1):\n",
- " print (list_date[5])\n",
- " if (day % 7 == 2):\n",
- " print (list_date[6])\n",
- " if (day % 7 == 3):\n",
- " print (list_date[0])\n",
- " if (day % 7 == 4):\n",
- " print (list_date[1])\n",
- " if (day % 7 == 5):\n",
- " print (list_date[2])\n",
- " if (day % 7 == 6):\n",
- " print (list_date[3])\n",
- " if (day % 7 == 0):\n",
- " print (list_date[4])\n",
- "if ( month == 4 or month == 7 ):\n",
- " if (day % 7 == 1):\n",
- " print (list_date[6])\n",
- " if (day % 7 == 2):\n",
- " print (list_date[0])\n",
- " if (day % 7 == 3):\n",
- " print (list_date[1])\n",
- " if (day % 7 == 4):\n",
- " print (list_date[2])\n",
- " if (day % 7 == 5):\n",
- " print (list_date[3])\n",
- " if (day % 7 == 6):\n",
- " print (list_date[4])\n",
- " if (day % 7 == 0):\n",
- " print (list_date[5])"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "아주 소스코드가 길어 수정하고 싶은 코드이다. 더 줄일 수 있지만 다른 과제가 있어 이대로 재출하였다.\n",
- "이 소스는 임의의 달의 1일이 어떤 요일에 따라 구분하여 if문을 복사붙여넣기 하여 구성한것이다."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "### ACM-ICPC 문제 11720번\n",
- "- 숫자의 합\n"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 39,
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "3\n",
- "456\n",
- "15\n"
- ]
- }
- ],
- "source": [
- "num = int(input())\n",
- "a =''\n",
- "sum = 0\n",
- "while ( len(a) != num ):\n",
- " a = a + input()\n",
- "for i in range (num):\n",
- " sum = sum + int(a[i])\n",
- "print(sum)"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "사용자로부터 입력을받는다. 그 입력을 받은만큼의 길이의 정수를 또한 공백없이 이어받는다. 그 후 받은 정수들의 sum값을 출력한다"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "<img src = \"Desktop\\hh.PNG\">"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "이번 스크립트 프로그래밍 첫 과제의 코딩의 양이 평소과제보다 많았다고 생각한다.\n",
- "파이썬이 빠르게 익숙해지는데 도움이 크게 되었다고 생각한다. ACM-ICPC 기출문제도 어렵지않고 적절하게 쉬운 난이도로 적절했다고 생각한다.\n",
- "백준사이트또한 아주 유용하다고 생각되었다. 많은 도움이 되는 내용이 많았다고 생각한다."
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {
- "collapsed": true
- },
- "source": [
- "..?"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {
- "collapsed": true
- },
- "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.1"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement