Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Python_101
Submodule Python_101 added at 06cd79
266 changes: 266 additions & 0 deletions function.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"id": "f793fa63",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"you entered:1\n",
"hello\n",
"you entered:2\n",
"welcome\n",
"you entered:3\n",
"goodbye\n"
]
}
],
"source": [
"\n",
"i = \" \"\n",
"while i !=3:\n",
" i= int(input(\"enter any command 1,2,3:\"))\n",
" print(f'you entered:{i}')\n",
" if i== 1:\n",
" print('hello')\n",
" elif i== 2:\n",
" print('welcome')\n",
" else:\n",
" print('goodbye')\n",
" \n",
"i= input(\"enter any command 1,2,3:\")\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2577ee1b",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"3\n",
"4\n",
"5\n"
]
}
],
"source": [
"#write a python that uses the 'for' loop for \n",
"#iterating through a list of elements and\n",
"#prints all the elements present in that list.\n",
"\n",
"\n",
"\n",
"\n",
"list=[1,2,3,4,5]\n",
"for i in list:\n",
" print(i)"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "f3591f09",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"dict_values(['Dog', 'Cat', 'Rabbit', 'Parrot', 'Mouse'])\n",
"dict_keys(['Item1', 'Item2', 'Item3', 'Item4', 'Item5'])\n",
"-------------------------------------------\n",
"Item1 : Dog\n",
"Item2 : Cat\n",
"Item3 : Rabbit\n",
"Item4 : Parrot\n",
"Item5 : Mouse\n"
]
}
],
"source": [
"# print one of the key values for dictinory using for loop \n",
"dict={\"Item1\":\"Dog\", \"Item2\":\"Cat\",\"Item3\":\"Rabbit\",\"Item4\":\"Parrot\",\"Item5\":\"Mouse\"}\n",
"\n",
"\n",
"print(dict.values()) #for printing values in dict\n",
"print(dict.keys()) #for printing keys in dict\n",
"\n",
"print(\"-------------------------------------------\")\n",
"\n",
"#for printing the dict items using loop \n",
"for i in dict:\n",
" print (i,\":\",dict[i])\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "9ad961fd",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1\n",
"2\n",
"3\n"
]
}
],
"source": [
"#define list and variable name search item \n",
"list_A =[1,2,3,4,5]\n",
"search_item = 4\n",
"for i in list_A: \n",
" if i== search_item:\n",
" break\n",
" else:\n",
" print(i)\n"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "7bf0b201",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"[1, 2, 3, 4, 5, 6, 6]\n",
"[1, 8, 2, 3, 4, 5, 6, 6]\n",
"[1, 8, 2, 3, 4, 5, 6, 6, 9, 10]\n"
]
}
],
"source": [
"#use append function in the list\n",
"#use the extent amd insert funtion in th elist\n",
"#observe the difference in the outputs afterwards\n",
"\n",
"list_1=[1,2,3,4,5,6]\n",
"list_1.append(6)\n",
"print(list_1)\n",
"\n",
"list_1.insert(1,8)\n",
"print(list_1)\n",
"\n",
"list_1.extend([9,10])\n",
"print(list_1)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "193b7b86",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#popular a list with the square of the number between 1-12\n",
"\n",
"list_of_square = []\n",
"for i in range(1,13):\n",
" list_of_square.append(i*i)\n",
"\n",
"list_of_square\n",
" \n"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "d48f743e",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144]"
]
},
"execution_count": 17,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"list_of_sq =[x*x for x in range(1,13)] #list comprehension\n",
"list_of_sq "
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "769d04a2",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[1, 4, 9, 25, 36, 49, 64, 81, 100, 121]"
]
},
"execution_count": 24,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"#use the sort(),remove(),pop() functions in the list of squares\n",
"#that you have created.\n",
"\n",
"\n",
"list_of_sq\n",
"list_of_sq.sort()\n",
"list_of_sq.remove(16)\n",
"list_of_sq.pop()\n",
"list_of_sq"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.13.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
90 changes: 90 additions & 0 deletions pyt_rutuja_3rdyr_10mar26.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"id": "a5c248ff",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"enter a valid value\n"
]
}
],
"source": [
"# you are writing a python program that processes user inputs\n",
"# and perform a mathematical operation \n",
"#the program attempts to:\n",
"#covert two string input into integers\n",
"#perform a division operation using the converted value\n",
"#handle possible runtime error using try-except\n",
"#or the program may attempt a illegal\n",
"# mathematical operatin (such as division by zero)\n",
"\n",
"\n",
"i = input(\"enter a value1:\")\n",
"j = input(\"enter a value2:\")\n",
"try:\n",
" value1=int(i)\n",
" value2=int(j)\n",
" v= value1/value2\n",
" print(f\"answer is {v}\")\n",
"\n",
"except ZeroDivisionError:\n",
"\n",
" print(\"enter a valid value\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2778483e",
"metadata": {},
"outputs": [],
"source": [
"# write \n",
"data = input(\"Enter numbers separated by space: \")\n",
"numbers = data.split()\n",
"valid = 0\n",
"invalid = 0\n",
"for n in numbers:\n",
" try:\n",
" num = int(n)\n",
" valid = valid + 1\n",
" if num % 2 == 0:\n",
" print(num, \"is Even number\")\n",
" else:\n",
" print(num, \"is Odd number\")\n",
" except:\n",
" print(n, \"Invalid input detected\")\n",
"invalid = invalid + 1\n",
"print(\"Total valid numbers:\", valid)\n",
"print(\"Total invalid inputs:\", invalid)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"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.13.9"
}
},
"nbformat": 4,
"nbformat_minor": 5
}