Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Ipynb

Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 6

{

"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "96ad9205",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"n? 10\n",
"30 2.9289682539682538 385 1.5497677311665408 22.218650793650795\n"
]
}
],
"source": [
"# 1 부터 n 까지 짝수의 합\n",

"# 1+2^2+3^2+…+𝑛^2\n",
"# 1 부터 n 까지 역수의 합: 1 + 1/2 + 1/3 + ... + 1/n\n",

"# 1+1/2^2 +1/3^2 +…+1/𝑛^2 \n",


"# 1/𝑛+2/(𝑛−1)+3/(𝑛−2)+…+(𝑛−2)/3+(𝑛−1)/2+𝑛/1\n",
"\n",
"sum1 = sum2 = sum3 = sum4 = sum5 = 0\n",
"n = int(input(\"n? \"))\n",
"for x in range(1, n+1):\n",
" if x % 2 == 0:\n",
" sum1 += x\n",
" sum2 += 1 / x\n",
" sum3 += x ** 2\n",
" sum4 += 1 / x ** 2\n",
" sum5 += x / (n - x + 1)\n",
"print(sum1, sum2, sum3, sum4, sum5)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f72e628b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3 4 5\n",
"5 12 13\n",
"6 8 10\n",
"7 24 25\n",
"8 15 17\n",
"9 12 15\n",
"9 40 41\n",
"10 24 26\n",
"11 60 61\n",
"12 16 20\n",
"12 35 37\n",
"13 84 85\n",
"14 48 50\n",
"15 20 25\n",
"15 36 39\n",
"16 30 34\n",
"16 63 65\n",
"18 24 30\n",
"18 80 82\n",
"20 21 29\n",
"20 48 52\n",
"21 28 35\n",
"21 72 75\n",
"24 32 40\n",
"24 45 51\n",
"24 70 74\n",
"25 60 65\n",
"27 36 45\n",
"28 45 53\n",
"28 96 100\n",
"30 40 50\n",
"30 72 78\n",
"32 60 68\n",
"33 44 55\n",
"33 56 65\n",
"35 84 91\n",
"36 48 60\n",
"36 77 85\n",
"39 52 65\n",
"39 80 89\n",
"40 42 58\n",
"40 75 85\n",
"42 56 70\n",
"45 60 75\n",
"48 55 73\n",
"48 64 80\n",
"51 68 85\n",
"54 72 90\n",
"57 76 95\n",
"60 63 87\n",
"60 80 100\n",
"65 72 97\n"
]
}
],

"# 1≤𝑎≤𝑏≤𝑐≤100 의 범위에 포함되는 모든 피타고라스의 수들을 출력하시오.\n",


"source": [

"for a in range(1, 101):\n",


" for b in range(a, 101):\n",
" for c in range(b, 101):\n",
" if a**2 + b**2 == c**2:\n",
" print(a, b, c)\n",
" break"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "b68ee4ca",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"**********\n",
"**********\n",
"**********\n",
"**********\n",
"**********\n",
"**********\n",
"**********\n",
"**********\n",
"**********\n",
"**********\n"
]
}
],
"source": [
"# '*'로 이루어진 10x10 사각형을 그리시오.\n",
"for x in range(10):\n",
" print('*' * 10)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "44341e61",
"metadata": {},
"outputs": [],
"source": [
"# 가로와 세로의 길이를 입력받아 '*'로 이루어진 가로 x 세로 사각형을 그리시오."
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "afa214e4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"n? 6\n",
" 1 2 3 4 5 6 \n",
" 7 8 9 10 11 12 \n",
" 13 14 15 16 17 18 \n",
" 19 20 21 22 23 24 \n",
" 25 26 27 28 29 30 \n",
" 31 32 33 34 35 36 \n"
]
}
],
"source": [
"# 2 부터 10 사이의 정수 n 을 입력받은 후, \n",
"# 1 부터 n2 까지의 연속된 수를 아래와 같이 행의 순서와 열의 순서로 각각 출력하라.\n",
"n = int(input(\"n? \"))\n",
"for row in range(n):\n",
" for col in range(n):\n",
" print(f\"{row*n + col + 1:3d}\", end=\" \")\n",
" print()"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "ff14196c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" 1 7 13 19 25 31 \n",
" 2 8 14 20 26 32 \n",
" 3 9 15 21 27 33 \n",
" 4 10 16 22 28 34 \n",
" 5 11 17 23 29 35 \n",
" 6 12 18 24 30 36 \n"
]
}
],
"source": [
"for row in range(n):\n",
" for col in range(n):\n",
" print(f\"{col*n + row + 1:3d}\", end=\" \")\n",
" print()"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "c1b03eaa",
"metadata": {},
"outputs": [
{
"ename": "Terminator",
"evalue": "",
"output_type": "error",
"traceback": [
"\
u001b[1;31m------------------------------------------------------------------------
---\u001b[0m",
"\u001b[1;31mTerminator\u001b[0m Traceback
(most recent call last)",
"\u001b[1;32m<ipython-input-8-5c70b2fd48a0>\u001b[0m in \u001b[0;36m<module>\
u001b[1;34m\u001b[0m\n\u001b[0;32m 10\u001b[0m \u001b[0mlength\u001b[0m \
u001b[1;33m+=\u001b[0m \u001b[1;36m10\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\
u001b[0m\u001b[0m\n\u001b[0;32m 11\u001b[0m \u001b[0mturtle\u001b[0m\
u001b[1;33m.\u001b[0m\u001b[0mmainloop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\
u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 12\
u001b[1;33m \u001b[0mturtle\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbye\u001b[0m\
u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\
u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m~\\miniconda3\\lib\\turtle.py\u001b[0m in \u001b[0;36mbye\
u001b[1;34m()\u001b[0m\n",
"\u001b[1;31mTerminator\u001b[0m: "
]
}
],
"source": [
"import turtle\n",
"\n",
"t = turtle.Turtle()\n",
"t.speed(0)\n",
"length = 10\n",
"for x in range(20):\n",
" for y in range(4):\n",
" t.left(90)\n",
" t.fd(length)\n",
" length += 10\n",
"turtle.mainloop()\n",
"turtle.bye()"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "a841c0b7",
"metadata": {},
"outputs": [
{
"ename": "Terminator",
"evalue": "",
"output_type": "error",
"traceback": [
"\
u001b[1;31m------------------------------------------------------------------------
---\u001b[0m",
"\u001b[1;31mTerminator\u001b[0m Traceback
(most recent call last)",
"\u001b[1;32m<ipython-input-9-061a4fd74a58>\u001b[0m in \u001b[0;36m<module>\
u001b[1;34m\u001b[0m\n\u001b[0;32m 7\u001b[0m \u001b[0mlength\u001b[0m \
u001b[1;33m+=\u001b[0m \u001b[1;36m5\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\
u001b[0m\u001b[0m\n\u001b[0;32m 8\u001b[0m \u001b[0mturtle\u001b[0m\
u001b[1;33m.\u001b[0m\u001b[0mmainloop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\
u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 9\
u001b[1;33m \u001b[0mturtle\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mbye\u001b[0m\
u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\
u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[1;32m~\\miniconda3\\lib\\turtle.py\u001b[0m in \u001b[0;36mbye\
u001b[1;34m()\u001b[0m\n",
"\u001b[1;31mTerminator\u001b[0m: "
]
}
],
"source": [
"t = turtle.Turtle()\n",
"t.speed(0)\n",
"length = 5\n",
"for x in range(53):\n",
" t.left(90)\n",
" t.fd(length)\n",
" length += 5\n",
"turtle.mainloop()\n",
"turtle.bye()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d27b3645",
"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.9.1"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

You might also like