0% found this document useful (0 votes)
17 views10 pages

Ipynb

Uploaded by

travel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views10 pages

Ipynb

Uploaded by

travel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 10

{

"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "8ebb19e9",
"metadata": {},
"outputs": [],
"source": [
"# 두 수를 전달받아 작은 수를 반환하는 함수 min2(x, y)를 작성하고, 테스트하라.\n",
"\n",
"def min2(x, y):\n",
" if x <= y:\n",
" return x\n",
" else:\n",
" return y"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "57d354b8",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"3\n",
"10\n"
]
}
],
"source": [
"print(min2(3, 5))\n",
"print(min2(20, 10))"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "d7154c71",
"metadata": {},
"outputs": [],
"source": [
"# 서로 다른 세 개의 숫자를 전달받아, 중간 값을 반환하는 함수 \n",
"# middle(x, y, z)를 작성하고, 테스트하라.\n",
"\n",
"def middle(x, y, z):\n",
" if x < y:\n",
" if z < x:\n",
" return x\n",
" elif z < y:\n",
" return z\n",
" else:\n",
" return y\n",
" else: # y < x\n",
" if z < y:\n",
" return y\n",
" elif z < x:\n",
" return z\n",
" else:\n",
" return x"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "43ac379a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"5\n",
"12\n",
"10\n"
]
}
],
"source": [
"print(middle(3, 5, 7))\n",
"print(middle(20, 10, 12))\n",
"print(middle(6, 20, 10))"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "874fe530",
"metadata": {},
"outputs": [],
"source": [
"# 원의 둘레를 계산하는 함수 get_peri(radius)를 정의하고 테스트한다. \n",
"# 만약 원의 반지름이 주어지지 않았으면 5.0 으로 간주한다. \n",
"import math\n",
"\n",
"def get_peri(radius = 5.0) :\n",
" return 2 * math.pi * radius"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "a0fb84ab",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"31.41592653589793\n",
"25.132741228718345\n"
]
}
],
"source": [
"print(get_peri())\n",
"print(get_peri(4.0))"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "80bd36bc",
"metadata": {},
"outputs": [],
"source": [
"# 두 개의 정수를 입력받은 다음, \n",
"# 덧셈, 뺄셈, 곱셈, 나눗셈의 결과를 반환하는 함수를 작성하라.\n",
"\n",
"def calc(x, y):\n",
" return x+y, x-y, x*y, x/y"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "ca7c7a15",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(8, 2, 15, 1.6666666666666667)\n"
]
}
],
"source": [
"print(calc(5, 3))"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "6d5a246d",
"metadata": {},
"outputs": [],
"source": [
"# 일회용 패스워드 생성기를 이용하여서 3 개의 패스워드를 생성하여 출력하는 \n",
"# 프로그램을 작성해보자. \n",
"\n",
"import random\n",
"\n",
"def otp():\n",
" letters = \"abcdefghijklmnopqrstuvwxyz0123456789\"\n",
" result = \"\"\n",
" for x in range(6):\n",
" result += random.choice(letters)\n",
" return result"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "241289d9",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"mj08c2\n",
"76u7rm\n",
"qzznc0\n",
"ayxuv1\n",
"efmqyt\n"
]
}
],
"source": [
"for _ in range(5):\n",
" print(otp())"
]
},
{
"cell_type": "code",
"execution_count": 13,
"id": "c4df6043",
"metadata": {},
"outputs": [],
"source": [
"sentence = \"This is a message from Yeungnam University\""
]
},
{
"cell_type": "code",
"execution_count": 14,
"id": "0da2c989",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['This', 'is', 'a', 'message', 'from', 'Yeungnam', 'University']\n"
]
}
],
"source": [
"print(sentence.split())"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "5a108e1a",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['This', 'is', 'a', 'message', 'from', 'Yeungnam', 'University']\n"
]
}
],
"source": [
"A = sentence.split()\n",
"print(A)"
]
},
{
"cell_type": "code",
"execution_count": 21,
"id": "0bc8f895",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['Yeungnam', 'University', 'This', 'message', 'is', 'from', 'a']"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(A, key=str.lower, reverse=True)"
]
},
{
"cell_type": "code",
"execution_count": 18,
"id": "d0b75f3c",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"84"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ord('T')"
]
},
{
"cell_type": "code",
"execution_count": 19,
"id": "2e6290f1",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"97"
]
},
"execution_count": 19,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"ord('a')"
]
},
{
"cell_type": "code",
"execution_count": 22,
"id": "bca175ed",
"metadata": {},
"outputs": [],
"source": [
"A = [('국어', 97), ('영어', 87), ('수학', 71), ('과학', 70), ('한국사', 78)]"
]
},
{
"cell_type": "code",
"execution_count": 23,
"id": "d5b9120b",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('과학', 70), ('국어', 97), ('수학', 71), ('영어', 87), ('한국사', 78)]"
]
},
"execution_count": 23,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(A)"
]
},
{
"cell_type": "code",
"execution_count": 24,
"id": "2c5dad74",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('과학', 70), ('수학', 71), ('한국사', 78), ('영어', 87), ('국어', 97)]"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(A, key=lambda x:x[1])"
]
},
{
"cell_type": "code",
"execution_count": 26,
"id": "0c9b8273",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('국어', 97), ('영어', 87), ('한국사', 78), ('수학', 71), ('과학', 70)]"
]
},
"execution_count": 26,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(A, key=lambda x:x[1], reverse=True)"
]
},
{
"cell_type": "code",
"execution_count": 27,
"id": "689fc5f9",
"metadata": {},
"outputs": [],
"source": [
"D = {\"김철수\":88, \"이영희\":92, \"박찬식\": 75, \"홍길동\":99}"
]
},
{
"cell_type": "code",
"execution_count": 28,
"id": "9a3082df",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"['김철수', '박찬식', '이영희', '홍길동']"
]
},
"execution_count": 28,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(D)"
]
},
{
"cell_type": "code",
"execution_count": 29,
"id": "1e7ff8fb",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('김철수', 88), ('박찬식', 75), ('이영희', 92), ('홍길동', 99)]"
]
},
"execution_count": 29,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(D.items())"
]
},
{
"cell_type": "code",
"execution_count": 30,
"id": "19040667",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('박찬식', 75), ('김철수', 88), ('이영희', 92), ('홍길동', 99)]"
]
},
"execution_count": 30,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(D.items(), key=lambda x:x[1])"
]
},
{
"cell_type": "code",
"execution_count": 31,
"id": "999ee3f4",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[('홍길동', 99), ('이영희', 92), ('김철수', 88), ('박찬식', 75)]"
]
},
"execution_count": 31,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"sorted(D.items(), key=lambda x:x[1], reverse=True)"
]
},
{
"cell_type": "code",
"execution_count": 36,
"id": "aa89ab14",
"metadata": {},
"outputs": [],
"source": [
"students = [\"kim\", \"lee\", \"park\", \"ahn\", \"cho\"]\n",
"math = [70, 80, 63, 67, 77]\n",
"eng = [95, 88, 90, 91, 92]"
]
},
{
"cell_type": "code",
"execution_count": 37,
"id": "700333d4",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[('kim', 70), ('lee', 80), ('park', 63), ('ahn', 67), ('cho', 77)]\n"
]
}
],
"source": [
"A = list(zip(students, math))\n",
"print(A)"
]
},
{
"cell_type": "code",
"execution_count": 40,
"id": "80936d87",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'lee'"
]
},
"execution_count": 40,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"max(A, key=lambda x:x[1])[0]"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2379595a",
"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