diff --git a/Notebook1.ipynb b/Notebook1.ipynb index f080647..be05784 100644 --- a/Notebook1.ipynb +++ b/Notebook1.ipynb @@ -2,7 +2,7 @@ "cells": [ { "cell_type": "code", - "execution_count": 1, + "execution_count": 2, "id": "73fb95c9", "metadata": {}, "outputs": [ @@ -10,28 +10,138 @@ "name": "stdout", "output_type": "stream", "text": [ - "7\n" + "6\n" ] } ], "source": [ "x = 3\n", - "y = 4\n", + "y = 3\n", "print(x + y)" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, + "id": "d33f497c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "PIYUSH\n", + "2\n", + "5.4\n" + ] + } + ], + "source": [ + "var=\"PIYUSH\"\n", + "var2=2\n", + "var3=5.4\n", + "print(var)\n", + "print(var2)\n", + "print(var3)\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, "id": "ca9af74b", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "list is contain number: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n", + "dict is contain differnt types of values: {1: 'Piyush', 2: 67, 3: 59.78, 4: True, 5: None}\n" + ] + } + ], + "source": [ + "list=[1,2,3,4,5,6,7,8,9,10]\n", + "dict={1:\"Piyush\",2:67,3:59.78,4:True,5:None}\n", + "print(\"list is contain number:\",list)\n", + "print(\"dict is contain differnt types of values: \",dict)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "id": "da81af67", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{None, True, False, 67, 'a', 45, 78, 23, 56, 'piyush'}\n" + ] + } + ], + "source": [ + "lista=[23,45,56,23,45,45,67,78,\"a\",\"piyush\",\"piyush\",None,True,True,False,\"a\",False]\n", + "set_lista=set(lista)\n", + "print(set_lista)\n", + "tuple_lista=tuple(lista)\n", + "\n", + "\n", + "# tht s cmnbkxcbhbxchjzbcjh vac \n", + "# bnvjhgSJDbcjhsd bvcjh \n", + "# sdnbvhcgsdycvuisbvk" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "d291a094", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12.2\n", + "12.2\n", + "12\n", + "True\n" + ] + }, + { + "ename": "NameError", + "evalue": "name 'date' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", + "\u001b[31mNameError\u001b[39m Traceback (most recent call last)", + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[12]\u001b[39m\u001b[32m, line 13\u001b[39m\n\u001b[32m 10\u001b[39m str_bool=\u001b[38;5;28mbool\u001b[39m(\u001b[38;5;28mstr\u001b[39m)\n\u001b[32m 11\u001b[39m \u001b[38;5;28mprint\u001b[39m(str_bool)\n\u001b[32m---> \u001b[39m\u001b[32m13\u001b[39m str_date=\u001b[43mdate\u001b[49m(\u001b[38;5;28mstr\u001b[39m)\n\u001b[32m 14\u001b[39m \u001b[38;5;28mprint\u001b[39m(str_date)\n", + "\u001b[31mNameError\u001b[39m: name 'date' is not defined" + ] + } + ], + "source": [ + "str=\"12.2\"\n", + "print(str)\n", + "\n", + "str_float=float(str)\n", + "print(str)\n", + "\n", + "float_int=int(str_float)\n", + "print(float_int)\n", + "\n", + "str_bool=bool(str)\n", + "print(str_bool)\n", + "\n", + "\n" + ] } ], "metadata": { "kernelspec": { - "display_name": "myenv", + "display_name": "pyt101", "language": "python", "name": "python3" }, @@ -45,7 +155,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.13.7" + "version": "3.14.2" } }, "nbformat": 4, diff --git a/Notebooktask1.ipynb b/Notebooktask1.ipynb new file mode 100644 index 0000000..e6cd731 --- /dev/null +++ b/Notebooktask1.ipynb @@ -0,0 +1,61 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "id": "4eacdf0b", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Welcome to the discount calculator!\n", + "Total discount : 150.0\n", + "Total amount after discount:850.0\n" + ] + } + ], + "source": [ + "# create a CLI based discount calculator \n", + "print(\"Welcome to the discount calculator!\")\n", + "amount = float(input(\"Enter the original amount: \"))\n", + "if amount > 500:\n", + " discount = 0.15\n", + "\n", + "elif amount > 1000:\n", + " discount = 0.10\n", + "\n", + "elif amount > 5000:\n", + " discount = 0.06\n", + "\n", + "else:\n", + " print(\"Invalid amount\")\n", + " \n", + "\n", + "print(f\"Total discount : {discount*amount}\\nTotal amount after discount:{amount-discount*amount}\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pyt101", + "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.14.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/Pyt_PiyushTungre_3rdyr_10march26.ipynb b/Pyt_PiyushTungre_3rdyr_10march26.ipynb new file mode 100644 index 0000000..62b7884 --- /dev/null +++ b/Pyt_PiyushTungre_3rdyr_10march26.ipynb @@ -0,0 +1,125 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "id": "010c6e93", + "metadata": {}, + "outputs": [], + "source": [ + "# assigment operator\n", + "\n", + "# =\n", + "# += and -=\n", + "# *=\n", + "# /=" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "088040aa", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "entered number is even\n" + ] + } + ], + "source": [ + "# extra question \n", + "# number=int(input(\"Enter a number:\"))\n", + "# try:\n", + "# if number%2==0:\n", + "# print(\"entered number is even\")\n", + "# else :\n", + "# print(\"entered number is odd\")\n", + " \n", + "\n", + "# not used in this question\n", + "# except ZeroDivisionError:\n", + "# print(\"Higher number then zero\") " + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "id": "1d0e3f34", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "11.0\n" + ] + } + ], + "source": [ + "i=input(\"Enter a number:\")\n", + "j=input(\"Enter a number:\")\n", + "try:\n", + "\n", + " number1=int(i)\n", + " number2=int(j)\n", + " result=number1/number2\n", + " print(result)\n", + "\n", + "except ZeroDivisionError:\n", + " print(\"enterd correct denominator value greater than zero\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "a82aea2a", + "metadata": {}, + "outputs": [], + "source": [ + "i= input(\"Enter sequence of number: \")\n", + "num = i.split()\n", + "valid_count = 0\n", + "invalid_count = 0\n", + "for j in num:\n", + " try:\n", + " n=int(j)\n", + " valid_count += 1\n", + " if n%2==0:\n", + " print(f\"{n} is even number\")\n", + " else:\n", + " print(f\"{n} is odd number\")\n", + "\n", + " except (TypeError,ValueError):\n", + " print(\"invalid input\")\n", + " invalid_count +=1 \n", + "\n", + "print(\"\\nTotal valid numbers:\", valid_count)\n", + "print(\"Total invalid inputs:\", invalid_count)" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "pyt101 (3.14.2)", + "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.14.2" + } + }, + "nbformat": 4, + "nbformat_minor": 5 +} diff --git a/task2.ipynb b/task2.ipynb new file mode 100644 index 0000000..5d5fb75 --- /dev/null +++ b/task2.ipynb @@ -0,0 +1,323 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 75, + "id": "f73485ba", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "You are in classroom 202\n", + "You are in classroom 201\n", + "You are in classroom 202\n", + "You aren't in classroom, go to class\n", + "You aren't in classroom, go to class\n", + "Program terminated\n" + ] + } + ], + "source": [ + " #take three predefine values and make one value which can terminate the program and rest of the other two values can perform other action\n", + " \n", + "\n", + "\n", + "input1 = int(input(\"choice the number between 1 to 10: \"))\n", + "\n", + "while input1 != 3:\n", + "\n", + " if input1 == 1:\n", + " print(\"You are in classroom 201\")\n", + "\n", + " elif input1 == 2:\n", + " print(\"You are in classroom 202\")\n", + "\n", + " else:\n", + " print(\"You aren't in classroom, go to class\")\n", + "\n", + " input1 = int(input(\"Enter a number: \"))\n", + "\n", + "print(\"Program terminated\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "6df4810a", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Element in 0 position of list 1\n", + "Element in 1 position of list 2\n", + "Element in 2 position of list 6\n" + ] + } + ], + "source": [ + "list=[1,2,6]\n", + "number=len(list)\n", + "\n", + "for i in range (number):\n", + " print(f\"Element in {i} position of list :{list[i]}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 13, + "id": "206e345c", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n" + ] + } + ], + "source": [ + "list=[1,2,3,4,5]\n", + "for i in list:\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "0ab14982", + "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": "5220c8d1", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n" + ] + } + ], + "source": [ + "# define a list and define a variable name search item\n", + "# used of break\n", + "# we search item 7\n", + "\n", + "list=[1,2,3,4,5,6,7,8,9]\n", + "\n", + "for i in list:\n", + " if i==7 :\n", + " break\n", + "\n", + " else:\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "id": "4ca885dc", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "8\n", + "9\n" + ] + } + ], + "source": [ + "# define a list and define a variable name search item\n", + "# used of continue\n", + "\n", + "# we search item 7\n", + "\n", + "list=[1,2,3,4,5,6,7,8,9]\n", + "\n", + "for i in list:\n", + " if i==7 :\n", + " continue\n", + "\n", + " else:\n", + " print(i)" + ] + }, + { + "cell_type": "code", + "execution_count": 42, + "id": "ab668ce2", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['9']\n", + "[45, '9']\n", + "[45, '9', 4, 5]\n" + ] + } + ], + "source": [ + "l=[]\n", + "input1=input(\"enter number\")\n", + "l.append(input1)\n", + "print(l)\n", + "\n", + "l.insert(0,45)\n", + "print(l)\n", + "\n", + "l.extend([4,5])\n", + "print(l)" + ] + }, + { + "cell_type": "code", + "execution_count": 46, + "id": "d6fdf4ce", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144]\n" + ] + } + ], + "source": [ + "# populate a list with the squares 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", + "print(list_of_square)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "id": "8f0be481", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144]" + ] + }, + "execution_count": 48, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "list_of_square=[x*x for x in range(1,13)] #list Comprehension\n", + "list_of_square" + ] + }, + { + "cell_type": "code", + "execution_count": 71, + "id": "e3654830", + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[1, 2, 3, 5, 6, 67, 8]" + ] + }, + "execution_count": 71, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "# used remove and pop function in the list\n", + "\n", + "li=[1,2,3,77,5,6,67,8,9]\n", + "li.sort\n", + "li.remove(77)\n", + "li.pop()\n", + "li" + ] + } + ], + "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 +}