Skip to content

Commit

Permalink
lab 2
Browse files Browse the repository at this point in the history
  • Loading branch information
pavanpej committed Aug 23, 2018
1 parent 7cfe48c commit cac7b4d
Show file tree
Hide file tree
Showing 6 changed files with 744 additions and 6 deletions.
42 changes: 36 additions & 6 deletions First-Notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Palindrome Program\n",
"# Palindrome Program\n",
"> For any value (number, string, etc.)"
]
},
Expand Down Expand Up @@ -53,7 +53,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## Factorial\n",
"# Factorial\n",
"> Only for integers."
]
},
Expand Down Expand Up @@ -165,7 +165,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"## .csv File Ops\n",
"# .csv File Ops\n",
"> - Input matrix from user and enter into a .csv file\n",
"> - Print contents of .csv file in matrix form"
]
Expand Down Expand Up @@ -240,12 +240,42 @@
"readCsv()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Nearest Palindrome\n",
"- Input: N (0 <= N <= 10^14)\n",
"- Output: The nearest palindrome to the given N. If N is a palindrome, then output N.\n",
"- If the difference between the two nearest palindrome is the closest, output is the lower value."
]
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 51,
"metadata": {},
"outputs": [],
"source": []
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10 \t 70 \t 101 \t 91\n"
]
}
],
"source": [
"# n = input(\"Enter a num\")\n",
"# n = '123456678'\n",
"n = '1070'\n",
"l = len(n)\n",
"h1, h2 = n[:l//2], n[(l+1)//2:]\n",
"h3 = n[:(l+1)//2]\n",
"n1 = str(h1[:-1])+h1[::-1]\n",
"n1 = int(n1)\n",
"n2 = str(int(h1) - 1)\n",
"n2 += h1[::-1][1:]\n",
"print(h1,'\\t',h2, '\\t', n1, '\\t', n2)"
]
}
],
"metadata": {
Expand Down
4 changes: 4 additions & 0 deletions pgm1.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sunny,warm,normal,strong,warm,same,yes
sunny,warm,high,strong,warm,same,yes
rainy,cold,normal,strong,warm,change,no
sunny,warm,high,strong,cool,change,yes
82 changes: 82 additions & 0 deletions pgm1.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Lab Program 1\n",
"> - Input: .csv file\n",
"> - Output: predicted hypothesis as .csv"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"['sunny', 'warm', 'normal', 'strong', 'warm', 'same']\n",
"['sunny', 'warm', '?', 'strong', 'warm', 'same']\n",
"['sunny', 'warm', '?', 'strong', 'warm', 'same']\n",
"['sunny', 'warm', '?', 'strong', '?', '?']\n"
]
}
],
"source": [
"import csv\n",
"\n",
"outFile = 'pgm1_out.csv'\n",
"out_fh = open(outFile,'w')\n",
"writer = csv.writer(out_fh)\n",
"\n",
"with open('pgm1.csv') as fh:\n",
" reader = csv.reader(fh)\n",
" h = ['0','0','0','0','0','0']\n",
" for row in reader:\n",
" if row[-1] == 'no':\n",
" print(h)\n",
" writer.writerows(','.join(h))\n",
" continue\n",
" for i in range(len(row)-1):\n",
" if h[i] != row[i] and h[i] != '0':\n",
" h[i] = '?'\n",
" elif h[i] == '0':\n",
" h[i] = row[i]\n",
" writer.writerows(','.join(h))\n",
" print(h)\n",
" "
]
},
{
"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
}
Loading

0 comments on commit cac7b4d

Please sign in to comment.