Advertisement
Guest User

Untitled

a guest
Sep 25th, 2017
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 16.06 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "### 문제1번\n",
  8. "- •a=\"Hello Python\" 문자열을 Slicing과 연결 연산자 (+)를 사용하여 \"Python Hello\"로 변경하시오.\n",
  9. "- ◾[주의] a 변수 자체에 \"Python Hello\" 문자열이 저장되어야 함\n"
  10. ]
  11. },
  12. {
  13. "cell_type": "code",
  14. "execution_count": 43,
  15. "metadata": {},
  16. "outputs": [
  17. {
  18. "name": "stdout",
  19. "output_type": "stream",
  20. "text": [
  21. "Python Hello\n"
  22. ]
  23. }
  24. ],
  25. "source": [
  26. "a = \"Hello Python\"\n",
  27. "a = a[6:] + \" \" + a[0:5]\n",
  28. "print(a)"
  29. ]
  30. },
  31. {
  32. "cell_type": "markdown",
  33. "metadata": {},
  34. "source": [
  35. "슬라이싱과 + 연산을 이용하여 문자열을 변경하였다."
  36. ]
  37. },
  38. {
  39. "cell_type": "markdown",
  40. "metadata": {},
  41. "source": [
  42. "### 문제2번\n",
  43. "- •b=\"Hello Python World\" 문자열을 Slicing과 연결 연산자 (+)를 사용하여 \"World Python Hello\"로 변경하시오.\n",
  44. "- ◾[주의] b 변수 자체에 \"Python Hello\" 문자열이 저장되어야 함 \n"
  45. ]
  46. },
  47. {
  48. "cell_type": "code",
  49. "execution_count": 44,
  50. "metadata": {},
  51. "outputs": [
  52. {
  53. "name": "stdout",
  54. "output_type": "stream",
  55. "text": [
  56. "World Python Hello\n",
  57. "Python Hello\n"
  58. ]
  59. }
  60. ],
  61. "source": [
  62. "b = \"Hello Python World\"\n",
  63. "str = b[6:12]\n",
  64. "str1 = ' '+b[0:5]\n",
  65. "str2 = b[13:] + ' '\n",
  66. "b = str + str1\n",
  67. "print ( str2+b)\n",
  68. "print (b)"
  69. ]
  70. },
  71. {
  72. "cell_type": "markdown",
  73. "metadata": {},
  74. "source": [
  75. "슬라이싱과 + 연산자를 사용하여 문자열을 수정하였다 하지만 b변수 자체에 world python hello가 들어가야하는것 같은데 오타인거 같았다"
  76. ]
  77. },
  78. {
  79. "cell_type": "markdown",
  80. "metadata": {},
  81. "source": [
  82. "### 문제3번\n",
  83. "- •c=\"Hello\"를 \"olleH\"로 변경하시오\n",
  84. "- ◾[주의] c 변수 자체에 \"olleH\" 문자열이 저장되어야 함\n"
  85. ]
  86. },
  87. {
  88. "cell_type": "code",
  89. "execution_count": 41,
  90. "metadata": {},
  91. "outputs": [
  92. {
  93. "name": "stdout",
  94. "output_type": "stream",
  95. "text": [
  96. "olleH\n"
  97. ]
  98. }
  99. ],
  100. "source": [
  101. "c = \"Hello\"\n",
  102. "c = c[::-1]\n",
  103. "print(c)"
  104. ]
  105. },
  106. {
  107. "cell_type": "markdown",
  108. "metadata": {},
  109. "source": [
  110. "스텝을 -1 나머지값들을 디폴트로 하면 문자열이 뒤집힌다."
  111. ]
  112. },
  113. {
  114. "cell_type": "markdown",
  115. "metadata": {},
  116. "source": [
  117. "### 문제4번\n",
  118. "\n",
  119. "- •s=\"python\"에 대해 다음 문제를 풀어보시오.\n",
  120. "- 1.s[0], s[0][0], s[0][0][0]은 각각 어떤 값이 나오는지 확인하고 그 이유를 나름대로 설명해 보시오.\n",
  121. "- 2.s[-100], s[100]은 값이 나오는지 에러가 나오는지 확인하고 그 결과에 대한 이유를 나름대로 설명해 보시오.\n",
  122. "- 3.s[-100, 100]은 값이 나오는지 에러가 나오는지 확인하고 그 결과에 대한 이유를 나름대로 설명해 보시오.\n",
  123. "- 4.s[1:-1]의 결과를 확인하고 그 결과에 대한 이유를 정확하게 설명하시오.\n",
  124. "- 5.s[3:-3]의 결과를 확인하고 그 결과에 대한 이유를 정확하게 설명하시오.\n",
  125. "\n"
  126. ]
  127. },
  128. {
  129. "cell_type": "code",
  130. "execution_count": 30,
  131. "metadata": {},
  132. "outputs": [
  133. {
  134. "name": "stdout",
  135. "output_type": "stream",
  136. "text": [
  137. "p p p\n",
  138. "\n"
  139. ]
  140. }
  141. ],
  142. "source": [
  143. "s = \"python\"\n",
  144. "print(s[0],s[0][0], s[0][0][0])\n",
  145. "print(s[3:-3])"
  146. ]
  147. },
  148. {
  149. "cell_type": "markdown",
  150. "metadata": {},
  151. "source": [
  152. "1. s[0],s[0][0], s[0][0][0]는 모두 p가 출력된다. \n",
  153. "2. s[-100], s[100]는 string index out of range라는 표시와 함께 오류가뜬다 이유는 s라는 문자열에 인덱스를 넘어가서 라고 생각한다.\n",
  154. "3. s[-100, 100] 는 string indices must be integer 오류가 나타난다\n",
  155. "4. s[1:-1]는 1번 인덱스부터 -1인덱스(포함하지않음) 까지이므로 ytho가 출력된다\n",
  156. "5. s[3:-3]는 3번 인덱스부터 -3번째(포함하지않음) 까지이므로 h(포함)부터 h(포함x) 범위이다 따라서 아무것도 출력되지않는다.\n",
  157. "- 1,3번의 경우 인덱싱과 슬라이싱에 대해서 알지만 마치 2차원이상의 배열처럼 인덱스가 주어진 문자열에 대해서는 수업 때 집중을 못한것인지는 모르겠지만 어떻게 작용하는지 모르겠다"
  158. ]
  159. },
  160. {
  161. "cell_type": "markdown",
  162. "metadata": {},
  163. "source": [
  164. "### 문제5번\n",
  165. "- •for문을 활용하여 1부터 100사이의 홀수를 출력하시오.\n"
  166. ]
  167. },
  168. {
  169. "cell_type": "code",
  170. "execution_count": 34,
  171. "metadata": {},
  172. "outputs": [
  173. {
  174. "name": "stdout",
  175. "output_type": "stream",
  176. "text": [
  177. "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 "
  178. ]
  179. }
  180. ],
  181. "source": [
  182. "for i in range (100):\n",
  183. " if ( i % 2 == 1 ):\n",
  184. " print (i, end=' ')"
  185. ]
  186. },
  187. {
  188. "cell_type": "markdown",
  189. "metadata": {},
  190. "source": [
  191. "만약에 0부터 99까지 2로 나누어 떨어지지 않는다면 소수이므로 출력한다."
  192. ]
  193. },
  194. {
  195. "cell_type": "markdown",
  196. "metadata": {},
  197. "source": [
  198. "### 문제6번\n",
  199. "- •while문을 활용하여 1부터 100사이의 짝수의 합을 계산하여 출력하시오."
  200. ]
  201. },
  202. {
  203. "cell_type": "code",
  204. "execution_count": 1,
  205. "metadata": {},
  206. "outputs": [
  207. {
  208. "name": "stdout",
  209. "output_type": "stream",
  210. "text": [
  211. "2550\n"
  212. ]
  213. }
  214. ],
  215. "source": [
  216. "i = 0\n",
  217. "sum = 0\n",
  218. "while ( i <= 100):\n",
  219. " if ( i % 2 == 0):\n",
  220. " sum += i\n",
  221. " i+=1\n",
  222. "print(sum)"
  223. ]
  224. },
  225. {
  226. "cell_type": "markdown",
  227. "metadata": {},
  228. "source": [
  229. "0부터 100까지 만약 i가 2로 나누어떨어진다면 sum += i를 수행한뒤 i+=1이 수행된다"
  230. ]
  231. },
  232. {
  233. "cell_type": "markdown",
  234. "metadata": {},
  235. "source": [
  236. "### 문제7번\n",
  237. "- •사용자로 부터 임의의 정수를 입력받고, 해당 숫자를 역순으로 출력하는 프로그램을 작성하시오\n",
  238. "- [실행 예]\n",
  239. "- 정수를 입력하세요: 3125\n",
  240. "- 숫자 역순은 5213 입니다.\n"
  241. ]
  242. },
  243. {
  244. "cell_type": "code",
  245. "execution_count": 36,
  246. "metadata": {},
  247. "outputs": [
  248. {
  249. "name": "stdout",
  250. "output_type": "stream",
  251. "text": [
  252. "3125\n",
  253. "5213\n"
  254. ]
  255. }
  256. ],
  257. "source": [
  258. "num = input()\n",
  259. "print(num[::-1])"
  260. ]
  261. },
  262. {
  263. "cell_type": "markdown",
  264. "metadata": {},
  265. "source": [
  266. "정수를 문자열의 형태로 입력받는다.\n",
  267. "슬라이싱의 스텝을 -1로 주고 나머지를 디폴트로하여 역순으로 출력한다"
  268. ]
  269. },
  270. {
  271. "cell_type": "markdown",
  272. "metadata": {},
  273. "source": [
  274. "### 문제8번\n",
  275. "- •사용자로 부터 정수를 입력받아서 1부터 그 사이에 존재하는 소수 (Prime number)를 출력하는 파이썬 프로그램을 작성하시오\n"
  276. ]
  277. },
  278. {
  279. "cell_type": "code",
  280. "execution_count": 37,
  281. "metadata": {},
  282. "outputs": [
  283. {
  284. "name": "stdout",
  285. "output_type": "stream",
  286. "text": [
  287. "16\n",
  288. "prime : 2\n",
  289. "prime : 3\n",
  290. "prime : 5\n",
  291. "prime : 7\n",
  292. "prime : 11\n",
  293. "prime : 13\n"
  294. ]
  295. }
  296. ],
  297. "source": [
  298. "def is_prime(num):\n",
  299. " i = 1\n",
  300. " count = 0\n",
  301. " while( i <= num):\n",
  302. " if ( num % i == 0):\n",
  303. " count+=1\n",
  304. " i+=1\n",
  305. " if ( count == 2):\n",
  306. " return 1\n",
  307. " else:\n",
  308. " return 0\n",
  309. "num = int(input())\n",
  310. "i = 0\n",
  311. "while ( i <= num ):\n",
  312. " if ( is_prime(i) == 1 ):\n",
  313. " print(\"prime : \" , i)\n",
  314. " i+=1\n",
  315. "\n"
  316. ]
  317. },
  318. {
  319. "cell_type": "markdown",
  320. "metadata": {},
  321. "source": [
  322. "is_prime 함수는 임의의 매개변수를 받아 소수라면1 아니라면 0을 판단하여 반환한다.\n",
  323. "반복문에서 입력받은 임의의 정수까지 is_prime(i)를 통해 1이 반환된다면 출력한다."
  324. ]
  325. },
  326. {
  327. "cell_type": "markdown",
  328. "metadata": {
  329. "collapsed": true
  330. },
  331. "source": [
  332. "### ACM-ICPC 문제 2439번\n",
  333. "- 별찍기-2\n"
  334. ]
  335. },
  336. {
  337. "cell_type": "code",
  338. "execution_count": 38,
  339. "metadata": {
  340. "scrolled": false
  341. },
  342. "outputs": [
  343. {
  344. "name": "stdout",
  345. "output_type": "stream",
  346. "text": [
  347. "5\n",
  348. " *\n",
  349. " **\n",
  350. " ***\n",
  351. " ****\n",
  352. "*****"
  353. ]
  354. }
  355. ],
  356. "source": [
  357. "ch = ' '\n",
  358. "ch2 = '*'\n",
  359. "num = int( input() );\n",
  360. "for i in range(num):\n",
  361. " if ( i>0):\n",
  362. " print ()\n",
  363. " for j in range(num-(i+1)):\n",
  364. " print (ch,end='')\n",
  365. " for k in range(num - (num-(i+1))):\n",
  366. " print (ch2, end='')\n"
  367. ]
  368. },
  369. {
  370. "cell_type": "markdown",
  371. "metadata": {},
  372. "source": [
  373. "공백과 * 문자 두개를 ch에 저장한다.\n",
  374. "사용자로부터 임의의 num을 입력받아 반복문을 실행한다.\n",
  375. "이중반복문안의 반복문 2개를 삽입하여 적절히 인덱스의 개수를 조절하여 출력할 수 있다."
  376. ]
  377. },
  378. {
  379. "cell_type": "markdown",
  380. "metadata": {},
  381. "source": [
  382. "### ACM-ICPC 문제 1924번\n",
  383. "- 2007년"
  384. ]
  385. },
  386. {
  387. "cell_type": "code",
  388. "execution_count": 45,
  389. "metadata": {
  390. "scrolled": true
  391. },
  392. "outputs": [
  393. {
  394. "name": "stdout",
  395. "output_type": "stream",
  396. "text": [
  397. "4 7\n",
  398. "SAT\n"
  399. ]
  400. }
  401. ],
  402. "source": [
  403. "a, b = input().split()\n",
  404. "month = int(a)\n",
  405. "day = int(b)\n",
  406. "list_date = [ 'MON','TUE','WED','THU','FRI','SAT','SUN']\n",
  407. "if ( month == 1 or month == 10 ):\n",
  408. " if (day % 7 == 1):\n",
  409. " print (list_date[0])\n",
  410. " if (day % 7 == 2):\n",
  411. " print (list_date[1])\n",
  412. " if (day % 7 == 3):\n",
  413. " print (list_date[2])\n",
  414. " if (day % 7 == 4):\n",
  415. " print (list_date[3])\n",
  416. " if (day % 7 == 5):\n",
  417. " print (list_date[4])\n",
  418. " if (day % 7 == 6):\n",
  419. " print (list_date[5])\n",
  420. " if (day % 7 == 0):\n",
  421. " print (list_date[6])\n",
  422. " \n",
  423. "if ( month == 5 ):\n",
  424. " if (day % 7 == 1):\n",
  425. " print (list_date[1])\n",
  426. " if (day % 7 == 2):\n",
  427. " print (list_date[2])\n",
  428. " if (day % 7 == 3):\n",
  429. " print (list_date[3])\n",
  430. " if (day % 7 == 4):\n",
  431. " print (list_date[4])\n",
  432. " if (day % 7 == 5):\n",
  433. " print (list_date[5])\n",
  434. " if (day % 7 == 6):\n",
  435. " print (list_date[6])\n",
  436. " if (day % 7 == 0):\n",
  437. " print (list_date[0])\n",
  438. "if ( month == 8 ):\n",
  439. " if (day % 7 == 1):\n",
  440. " print (list_date[2])\n",
  441. " if (day % 7 == 2):\n",
  442. " print (list_date[3])\n",
  443. " if (day % 7 == 3):\n",
  444. " print (list_date[4])\n",
  445. " if (day % 7 == 4):\n",
  446. " print (list_date[5])\n",
  447. " if (day % 7 == 5):\n",
  448. " print (list_date[6])\n",
  449. " if (day % 7 == 6):\n",
  450. " print (list_date[0])\n",
  451. " if (day % 7 == 0):\n",
  452. " print (list_date[1])\n",
  453. "if ( month == 2 or month == 3 or month == 11 ):\n",
  454. " if (day % 7 == 1):\n",
  455. " print (list_date[3])\n",
  456. " if (day % 7 == 2):\n",
  457. " print (list_date[4])\n",
  458. " if (day % 7 == 3):\n",
  459. " print (list_date[5])\n",
  460. " if (day % 7 == 4):\n",
  461. " print (list_date[6])\n",
  462. " if (day % 7 == 5):\n",
  463. " print (list_date[0])\n",
  464. " if (day % 7 == 6):\n",
  465. " print (list_date[1])\n",
  466. " if (day % 7 == 0):\n",
  467. " print (list_date[2])\n",
  468. "if ( month == 6 ):\n",
  469. " if (day % 7 == 1):\n",
  470. " print (list_date[4])\n",
  471. " if (day % 7 == 2):\n",
  472. " print (list_date[5])\n",
  473. " if (day % 7 == 3):\n",
  474. " print (list_date[6])\n",
  475. " if (day % 7 == 4):\n",
  476. " print (list_date[0])\n",
  477. " if (day % 7 == 5):\n",
  478. " print (list_date[1])\n",
  479. " if (day % 7 == 6):\n",
  480. " print (list_date[2])\n",
  481. " if (day % 7 == 0):\n",
  482. " print (list_date[3])\n",
  483. "if ( month == 9 or month == 12 ):\n",
  484. " if (day % 7 == 1):\n",
  485. " print (list_date[5])\n",
  486. " if (day % 7 == 2):\n",
  487. " print (list_date[6])\n",
  488. " if (day % 7 == 3):\n",
  489. " print (list_date[0])\n",
  490. " if (day % 7 == 4):\n",
  491. " print (list_date[1])\n",
  492. " if (day % 7 == 5):\n",
  493. " print (list_date[2])\n",
  494. " if (day % 7 == 6):\n",
  495. " print (list_date[3])\n",
  496. " if (day % 7 == 0):\n",
  497. " print (list_date[4])\n",
  498. "if ( month == 4 or month == 7 ):\n",
  499. " if (day % 7 == 1):\n",
  500. " print (list_date[6])\n",
  501. " if (day % 7 == 2):\n",
  502. " print (list_date[0])\n",
  503. " if (day % 7 == 3):\n",
  504. " print (list_date[1])\n",
  505. " if (day % 7 == 4):\n",
  506. " print (list_date[2])\n",
  507. " if (day % 7 == 5):\n",
  508. " print (list_date[3])\n",
  509. " if (day % 7 == 6):\n",
  510. " print (list_date[4])\n",
  511. " if (day % 7 == 0):\n",
  512. " print (list_date[5])"
  513. ]
  514. },
  515. {
  516. "cell_type": "markdown",
  517. "metadata": {},
  518. "source": [
  519. "아주 소스코드가 길어 수정하고 싶은 코드이다. 더 줄일 수 있지만 다른 과제가 있어 이대로 재출하였다.\n",
  520. "이 소스는 임의의 달의 1일이 어떤 요일에 따라 구분하여 if문을 복사붙여넣기 하여 구성한것이다."
  521. ]
  522. },
  523. {
  524. "cell_type": "markdown",
  525. "metadata": {},
  526. "source": [
  527. "### ACM-ICPC 문제 11720번\n",
  528. "- 숫자의 합\n"
  529. ]
  530. },
  531. {
  532. "cell_type": "code",
  533. "execution_count": 39,
  534. "metadata": {},
  535. "outputs": [
  536. {
  537. "name": "stdout",
  538. "output_type": "stream",
  539. "text": [
  540. "3\n",
  541. "456\n",
  542. "15\n"
  543. ]
  544. }
  545. ],
  546. "source": [
  547. "num = int(input())\n",
  548. "a =''\n",
  549. "sum = 0\n",
  550. "while ( len(a) != num ):\n",
  551. " a = a + input()\n",
  552. "for i in range (num):\n",
  553. " sum = sum + int(a[i])\n",
  554. "print(sum)"
  555. ]
  556. },
  557. {
  558. "cell_type": "markdown",
  559. "metadata": {},
  560. "source": [
  561. "사용자로부터 입력을받는다. 그 입력을 받은만큼의 길이의 정수를 또한 공백없이 이어받는다. 그 후 받은 정수들의 sum값을 출력한다"
  562. ]
  563. },
  564. {
  565. "cell_type": "markdown",
  566. "metadata": {},
  567. "source": [
  568. "<img src = \"Desktop\\hh.PNG\">"
  569. ]
  570. },
  571. {
  572. "cell_type": "markdown",
  573. "metadata": {
  574. "collapsed": true
  575. },
  576. "source": [
  577. "이번 스크립트 프로그래밍 첫 과제의 코딩의 양이 평소과제보다 많았다고 생각한다.\n",
  578. "파이썬이 빠르게 익숙해지는데 도움이 크게 되었다고 생각한다. ACM-ICPC 기출문제도 어렵지않고 적절하게 쉬운 난이도로 적절했다고 생각한다.\n",
  579. "백준사이트또한 아주 유용하다고 생각되었다. 많은 도움이 되는 내용이 많았다고 생각한다."
  580. ]
  581. },
  582. {
  583. "cell_type": "markdown",
  584. "metadata": {
  585. "collapsed": true
  586. },
  587. "source": [
  588. "..?"
  589. ]
  590. },
  591. {
  592. "cell_type": "code",
  593. "execution_count": null,
  594. "metadata": {
  595. "collapsed": true
  596. },
  597. "outputs": [],
  598. "source": []
  599. }
  600. ],
  601. "metadata": {
  602. "kernelspec": {
  603. "display_name": "Python 3",
  604. "language": "python",
  605. "name": "python3"
  606. },
  607. "language_info": {
  608. "codemirror_mode": {
  609. "name": "ipython",
  610. "version": 3
  611. },
  612. "file_extension": ".py",
  613. "mimetype": "text/x-python",
  614. "name": "python",
  615. "nbconvert_exporter": "python",
  616. "pygments_lexer": "ipython3",
  617. "version": "3.6.1"
  618. }
  619. },
  620. "nbformat": 4,
  621. "nbformat_minor": 2
  622. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement