Answer To: id,ct,secs,cl 1000025,5,2,2 1002945,5,7,2 1015425,3,2,2 1016277,6,3,2 1017023,4,2,2 1017122,8,7,4...
Karthi answered on Sep 20 2021
{
"cells": [
{
"cell_type": "markdown",
"source": [
"# All imports here"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 2,
"source": [
"import pandas as pd\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import csv"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Question 1: Palindrome"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 3,
"source": [
"def reverse(text):\n",
" return text[::-1]\n",
"\n",
"def is_palindrome(text):\n",
" return text == reverse(text)\n",
"\n",
"def check_palidrome(text):\n",
" if(is_palindrome(text)):\n",
" print('True')\n",
" else:\n",
" print('False')\n",
"\n",
"check_palidrome(text=\"radar\") \n",
"check_palidrome(text=\"CS5644\")\n",
"check_palidrome(text=\"madam\")\n",
"check_palidrome(text=\"rar\")\n",
"check_palidrome(text=\"mouse\") "
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"True\n",
"False\n",
"True\n",
"True\n",
"False\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Question 2: Caesar cipher cryptography"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 4,
"source": [
"def rot13_decode(input_string):\n",
" shift = 13 \n",
" plain_text = \"\"\n",
" for c in input_string:\n",
" if c.isupper():\n",
" c_unicode = ord(c)\n",
" c_index = ord(c) - ord(\"A\")\n",
" new_index = (c_index - shift) % 26\n",
" new_unicode = new_index + ord(\"A\")\n",
" new_character = chr(new_unicode)\n",
" plain_text = plain_text + new_character\n",
" else:\n",
" plain_text += c\n",
"\n",
" print(\"Encrypted text:\",input_string)\n",
"\n",
" print(\"Decrypted text:\",plain_text)"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 5,
"source": [
"def rot13_encode(input_string):\n",
" shift = 13\n",
" encryption = \"\"\n",
"\n",
" for c in input_string:\n",
" if c.isupper():\n",
" c_unicode = ord(c)\n",
" c_index = ord(c) - ord(\"A\")\n",
" new_index = (c_index + shift) % 26\n",
" new_unicode = new_index + ord(\"A\")\n",
" new_character = chr(new_unicode)\n",
" encryption = encryption + new_character\n",
"\n",
" else:\n",
" encryption += c\n",
" \n",
" print(\"Plain text:\",input_string)\n",
"\n",
" print(\"Encrypted text:\",encryption)"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 6,
"source": [
"rot13_decode(input_string=\"PNRFNE PVCURE? ZHPU CERSRE PNRFNE FNYNQ\")"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"Encrypted text: PNRFNE PVCURE? ZHPU CERSRE PNRFNE FNYNQ\n",
"Decrypted text: CAESAR CIPHER? MUCH PREFER CAESAR SALAD\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Question 3: Word Counter"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 7,
"source": [
"def word_counter(input_string):\n",
" list1 = []\n",
" res = len(input_string.split())\n",
" total_count = str(res)\n",
" int_count = int(total_count)\n",
" for word in input_string:\n",
" if word[0].isupper():\n",
" list1.append(word)\n",
" \n",
" print (\"The number of words in string are : \" + str(res))\n",
" print(\"Letters starting with captial letter\", len(list1))\n",
" print(\"Letters starting with lower case\", (int_count - len(list1)))"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 8,
"source": [
"word_counter(input_string=\"The Zen is here for You\")"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"The number of words in string are : 6\n",
"Letters starting with captial letter 3\n",
"Letters starting with lower case 3\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Data Exploration \n",
"\n",
"# Question 4: Read csv file"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 9,
"source": [
"clump_thickness_benign = []\n",
"clump_thickness_malignant = []\n",
"clump_thickness = []\n",
"cell_benign = []\n",
"cell_malignant = []\n",
"malignant = []\n",
"benign = []\n",
"with open(\"data.csv\", \"r\") as csv_file:\n",
" csv_reader = csv.reader(csv_file, delimiter=',')\n",
" for lines in csv_reader:\n",
" if lines[3] == '2':\n",
" benign.append(lines)\n",
" clump_thickness_benign.append(lines[1])\n",
" clump_thickness.append(lines[1])\n",
" cell_benign.append(lines[2])\n",
" else:\n",
" malignant.append(lines)\n",
" clump_thickness_malignant.append(lines[1])\n",
" clump_thickness.append(lines[1])\n",
" cell_malignant.append(lines[2])\n",
"print(clump_thickness_benign)\n",
"print(clump_thickness_malignant)\n",
"print(clump_thickness)\n",
"\n",
"print(cell_benign)\n",
"print(cell_malignant)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"['5', '5', '3', '6', '4', '1', '2', '4', '1', '2', '1', '4', '4', '6', '3', '1', '3', '5', '2', '3', '2', '2', '3', '2', '6', '6', '1', '1', '4', '1', '1', '4', '1', '5', '1', '1', '1', '5', '3', '2', '2', '4', '3', '4', '2', '1', '3', '4', '1', '2', '1', '2', '5', '4', '1', '1', '3', '1', '1', '3', '1', '1', '3', '1', '5', '2', '3', '3', '5', '4', '3', '4', '1', '3', '2', '1', '2', '1', '1', '3', '1', '4', '1', '1', '2', '1', '4', '3', '1', '5', '4', '3', '1', '3', '1', '1', '2', '4', '1', '1', '6', '2', '1', '5', '1', '3', '8', '5', '1', '3', '1', '5', '1', '1', '5', '1', '1', '1', '6', '1', '1', '1', '8', '3', '3', '5', '3', '2', '1', '1', '5', '4', '3', '1', '5', '1', '5', '3', '3', '3', '1', '1', '3', '2', '3', '1', '1', '1', '5', '5', '8', '1', '1', '1', '1', '3', '2', '1', '1', '1', '4', '1', '4', '3', '1', '3', '1', '5', '5', '1', '1', '1', '2', '1', '1', '5', '1', '5', '2', '3', '1', '4', '3', '4', '2', '2', '1', '1', '4', '1', '5', '1', '1', '1', '3', '5', '1', '3', '2', '2', '3', '5', '5', '1', '3', '1', '3', '3', '4', '3', '1', '3', '5', '3', '1', '1', '4', '1', '2', '3', '1', '1', '5', '3', '1', '5', '2', '3', '4', '5', '3', '5', '1', '5', '3', '4', '4', '5', '5', '1', '5', '2', '1', '5', '4', '5', '3', '2', '5', '5', '5', '3', '4', '4', '1', '3', '6', '6', '4', '5', '3', '4', '4', '5', '5', '5', '5', '1', '3', '4', '5', '3', '1', '4', '4', '6', '4', '4', '4', '1', '3', '1', '5', '2', '1', '5', '5', '3', '1', '3', '1', '4', '3', '3', '6', '4', '4', '1', '3', '2', '1', '5', '4', '6', '5', '3', '5', '4', '2', '5', '2', '3', '1', '4', '3', '4', '5', '5', '2', '5', '5', '1', '3', '4', '3', '4', '3', '1', '5', '1', '1', '1', '5', '3', '5', '1', '5', '5', '5', '5', '4', '5', '3', '5', '3', '1', '4', '4', '5', '2', '2', '4', '3', '1', '5', '3', '6', '7', '1', '5', '3', '2', '2', '4', '6', '5', '3', '3', '4', '4', '4', '3', '3', '1', '3', '1', '1', '3', '3', '1', '5', '4', '3', '3', '5', '5', '1', '1', '1', '1', '3', '1', '5', '3', '3', '2', '1', '4', '1', '5', '1', '2', '5', '1', '1', '1', '3', '4', '1', '3', '3', '3', '2']\n",
"['ct', '8', '5', '8', '7', '10', '7', '10', '8', '5', '10', '10', '5', '2', '10', '6', '5', '10', '3', '7', '9', '5', '10', '5', '10', '10', '8', '8', '5', '9', '5', '9', '6', '10', '5', '8', '6', '9', '10', '3', '5', '3', '3', '9', '7', '10', '2', '8', '10', '7', '10', '1', '8', '10', '10', '4', '10', '5', '5', '7', '8', '5', '9', '3', '8', '7', '10', '5', '9', '10', '5', '10', '6', '8', '5', '5', '5', '5', '8', '1', '10', '5', '10', '7', '9', '10', '5', '10', '8', '8', '10', '10', '8', '6', '10', '4', '7', '10', '10', '8', '10', '7', '6', '10', '10', '9', '8', '10', '8', '8', '10', '10', '5', '8', '10', '7', '3', '10', '8', '7', '10', '1', '10', '7', '8', '10', '6', '5', '8', '10', '5', '9', '8', '10', '8', '10', '7', '8', '5', '6', '7', '5', '10', '8', '10', '10', '5', '8', '6', '8', '10', '7', '3', '4', '2', '5', '8', '8', '10', '6', '3', '6', '5', '10', '7', '10', '3', '10', '8', '8', '10', '9', '8', '10', '10', '10', '5', '4', '10', '10', '8', '10', '10', '6', '4', '9', '8', '10', '3', '6', '5', '5', '8', '6', '4', '4', '10', '7', '7', '6', '7', '5', '8', '10', '8', '7', '10', '5', '6', '8', '9', '4', '2', '10', '4', '5', '5', '10', '5', '10', '5', '4', '8', '10', '5', '7', '5', '5', '3', '10', '5', '5', '4']\n",
"['ct', '5', '5', '3', '6', '4', '8', '1', '2', '4', '1', '2', '5', '1', '8', '7', '4', '4', '10', '6', '7', '10', '3', '8', '1', '5', '3', '5', '2', '3', '2', '10', '2', '3', '2', '10', '6', '5', '2', '6', '10', '6', '5', '10', '1', '3', '1', '4', '7', '9', '5', '10', '5', '10', '10', '8', '8', '5', '9', '5', '1', '9', '6', '1', '10', '4', '5', '8', '1', '5', '6', '1', '9', '10', '1', '1', '5', '3', '2', '2', '4', '3', '3', '5', '3', '3', '4', '2', '1', '3', '4', '1', '2', '1', '2', '5', '9', '7', '10', '2', '4', '8', '10', '7', '10', '1', '1', '1', '8', '10', '10', '3', '1', '4', '1', '3', '1', '10', '5', '5', '1', '7', '3', '8', '1', '5', '2', '5', '3', '3', '5', '4', '3', '4', '1', '3', '2', '9', '1', '2', '1', '3', '1', '3', '8', '1', '7', '10', '4', '1', '5', '1', '2', '1', '9', '10', '4', '3', '1', '5', '4', '5', '10', '3', '1', '3', '1', '1', '6', '8', '5', '2', '5', '4', '5', '1', '1', '6', '5', '8', '2', '1', '10', '5', '1', '10', '7', '5', '1', '3', '8', '5', '1', '3', '9', '10', '1', '5', '1', '5', '10', '1', '5', '8', '8', '1', '10', '10', '8', '1', '1', '6', '6', '1', '10', '4', '7', '10', '1', '10', '8', '1', '10', '7', '6', '8', '10', '3', '3', '10', '9', '8', '10', '5', '3', '2', '1', '1', '5', '8', '8', '4', '3', '1', '10', '5', '10', '5', '8', '10', '7', '3', '10', '1', '8', '5', '7', '3', '3', '3', '1', '1', '10', '3', '2', '1', '10', '7', '8', '10', '3', '6', '5', '1', '1', '8', '10', '1', '5', '5', '5', '8', '9', '8', '1', '10', '1', '8', '10', '1', '1', '7', '3', '2', '1', '8', '1', '1', '4', '5', '6', '1', '4', '7', '3', '5', '1', '3', '10', '1', '8', '10', '10', '5', '5', '5', '8', '1', '6', '1', '8', '10', '1', '2', '1', '7', '1', '5', '1', '3', '4', '5', '2', '3', '2', '1', '4', '5', '8', '8', '10', '6', '3', '3', '4', '2', '2', '6', '5', '1', '1', '4', '1', '5', '1', '1', '1', '3', '5', '1', '10', '3', '2', '2', '3', '7', '5', '5', '1', '10', '3', '1', '3', '3', '4', '3', '1', '3', '3', '5', '3', '1', '1', '4', '1', '2', '3', '1', '1', '10', '5', '8', '3', '8', '1', '5', '2', '3', '10', '4', '5', '3', '9', '5', '8', '1', '5', '3', '10', '10', '4', '4', '5', '10', '5', '1', '5', '2', '1', '5', '5', '4', '5', '3', '4', '2', '10', '10', '8', '5', '5', '5', '3', '4', '4', '10', '10', '6', '1', '3', '6', '6', '4', '5', '3', '4', '4', '5', '4', '5', '5', '9', '8', '5', '1', '3', '10', '3', '6', '5', '4', '5', '5', '3', '1', '4', '4', '6', '4', '4', '4', '1', '3', '8', '1', '5', '2', '1', '5', '5', '3', '6', '4', '1', '3', '4', '1', '4', '10', '7', '3', '3', '6', '4', '7', '4', '1', '3', '2', '1', '5', '4', '6', '5', '3', '5', '4', '2', '5', '6', '2', '7', '3', '1', '4', '3', '4', '5', '5', '2', '5', '5', '1', '3', '4', '5', '3', '4', '8', '10', '8', '7', '3', '1', '10', '5', '1', '1', '1', '5', '5', '6', '3', '5', '1', '8', '5', '9', '5', '4', '2', '10', '5', '4', '5', '4', '5', '3', '5', '3', '1', '4', '5', '5', '10', '4', '5', '5', '10', '5', '2', '2', '4', '3', '1', '5', '3', '6', '7', '1', '5', '3', '4', '2', '2', '4', '6', '5', '8', '3', '3', '10', '4', '4', '4', '3', '3', '1', '3', '1', '1', '5', '3', '3', '1', '5', '4', '3', '3', '5', '5', '7', '1', '1', '1', '1', '3', '1', '5', '3', '5', '5', '3', '3', '2', '1', '4', '1', '5', '1', '2', '10', '5', '5', '1', '1', '1', '3', '4', '1', '3', '3', '3', '2', '5', '4']\n",
"['2', '7', '2', '3', '2', '2', '2', '2', '1', '2', '2', '2', '2', '2', '2', '2', '1', '2', '2', '1', '2', '2', '2', '2', '1', '6', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '1', '2', '2', '2', '3', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '4', '2', '2', '2', '2', '10', '2', '2', '2', '3', '2', '2', '2', '2', '1', '2', '2', '2', '2', '2', '3', '8', '1', '2', '2', '2', '2', '3', '2', '2', '1', '2', '2', '2', '1', '2', '2', '2', '2', '2', '1', '2', '2', '1', '2', '2', '2', '2', '4', '2', '2', '2', '2', '2', '2', '1', '1', '2', '2', '2', '2', '2', '2', '1', '3', '3', '2', '2', '1', '2', '2', '2', '2', '2', '2', '2', '5', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '2', '2', '2', '4', '2', '5', '2', '2', '2', '2', '2', '3', '2', '2', '1', '7', '5', '6', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '1', '2', '2', '7', '2', '3', '4', '2', '2', '2', '2', '1', '3', '2', '2', '2', '2', '1', '3', '4', '2', '2', '2', '2', '3', '3', '3', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '1', '2', '3', '2', '2', '5', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '2', '2', '2', '1', '2', '2', '3', '2', '2', '2', '2', '2', '2', '2', '1', '2', '1', '2', '2', '2', '2', '2', '2', '1', '2', '2', '1', '1', '1', '4', '1', '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '1', '1', '2', '3', '3', '2', '2', '2', '1', '2', '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '1', '2', '2', '2', '2', '2', '1', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '2', '2', '2', '2', '2', '2', '2', '2', '1', '2', '1', '2', '2', '2', '2', '1', '2', '2', '1', '2', '2', '3', '2', '2', '1', '3', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '2', '2', '2', '2', '2', '2', '8', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '2', '3', '2']\n",
"['secs', '7', '2', '7', '6', '4', '5', '6', '2', '2', '8', '6', '2', '6', '3', '8', '10', '8', '4', '4', '2', '2', '3', '10', '8', '4', '3', '5', '6', '2', '3', '10', '5', '3', '8', '4', '10', '6', '3', '8', '10', '5', '5', '10', '5', '10', '2', '6', '10', '3', '2', '8', '5', '2', '10', '4', '10', '8', '9', '4', '5', '8', '4', '6', '10', '6', '4', '3', '6', '5', '8', '6', '8', '3', '10', '8', '6', '5', '4', '5', '6', '5', '6', '10', '5', '10', '6', '7', '5', '4', '7', '3', '5', '6', '10', '1', '3', '3', '4', '3', '10', '3', '6', '5', '8', '6', '6', '3', '5', '2', '2', '3', '10', '5', '6', '10', '3', '3', '3', '3', '3', '4', '2', '2', '8', '10', '4', '6', '2', '2', '6', '4', '4', '9', '3', '4', '4', '10', '5', '6', '5', '2', '2', '6', '5', '2', '4', '3', '4', '2', '2', '10', '5', '3', '7', '3', '10', '8', '3', '10', '6', '8', '5', '4', '2', '3', '6', '8', '3', '10', '10', '10', '4', '3', '6', '4', '6', '6', '2', '5', '6', '6', '4', '4', '4', '10', '5', '6', '3', '3', '3', '6', '7', '3', '3', '4', '3', '4', '4', '4', '4', '5', '6', '6', '8', '3', '4', '5', '4', '6', '6', '4', '4', '3', '4', '4', '5', '5', '10', '3', '5', '7', '5', '7', '10', '3', '6', '5', '5', '5', '4', '7', '3']\n"
]
}
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 10,
"source": [
"clump_thickness_malignant.remove('ct')\n",
"clump_thickness.remove('ct')\n",
"cell_malignant.remove('secs')"
],
"outputs": [],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 11,
"source": [
"print(clump_thickness_malignant)"
],
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"['8', '5', '8', '7', '10', '7', '10', '8', '5', '10', '10', '5', '2', '10', '6', '5', '10', '3', '7', '9', '5', '10', '5', '10', '10', '8', '8', '5', '9', '5', '9', '6', '10', '5', '8', '6', '9', '10', '3', '5', '3', '3', '9', '7', '10', '2', '8', '10', '7', '10', '1', '8', '10', '10', '4', '10', '5', '5', '7', '8', '5', '9', '3', '8', '7', '10', '5', '9', '10', '5', '10', '6', '8', '5', '5', '5', '5', '8', '1', '10', '5', '10', '7', '9', '10', '5', '10', '8', '8', '10', '10', '8', '6', '10', '4', '7', '10', '10', '8', '10', '7', '6', '10', '10', '9', '8', '10', '8', '8', '10', '10', '5', '8', '10', '7', '3', '10', '8', '7', '10', '1', '10', '7', '8', '10', '6', '5', '8', '10', '5', '9', '8', '10', '8', '10', '7', '8', '5', '6', '7', '5', '10', '8', '10', '10', '5', '8', '6', '8', '10', '7', '3', '4', '2', '5', '8', '8', '10', '6', '3', '6', '5', '10', '7', '10', '3', '10', '8', '8', '10', '9', '8', '10', '10', '10', '5', '4', '10', '10', '8', '10', '10', '6', '4', '9', '8', '10', '3', '6', '5', '5', '8', '6', '4', '4', '10', '7', '7', '6', '7', '5', '8', '10', '8', '7', '10', '5', '6', '8', '9', '4', '2', '10', '4', '5', '5', '10', '5', '10', '5', '4', '8', '10', '5', '7', '5', '5', '3', '10', '5', '5', '4']\n"
]
}
],
"metadata": {}
},
{
"cell_type": "markdown",
"source": [
"# Question 5: Histogram of clump thickness"
],
"metadata": {}
},
{
"cell_type": "code",
"execution_count": 12,
"source": [
"plt.hist(clump_thickness_benign, label=['benign'])\n",
"plt.hist(clump_thickness_malignant, label=['malignant'])\n",
"plt.xlabel(\"Number of people\")\n",
"plt.ylabel('Clump thicknes')\n",
"plt.title('Comparison between malignant and benign breast camcer')\n",
"plt.legend(loc=\"upper right\")\n",
"plt.show()"
],
"outputs": [
{
"output_type": "display_data",
"data": {
"image/png":...