diff --git a/int_assignment.ipynb b/int_assignment.ipynb index 6090fff..fadd31a 100644 --- a/int_assignment.ipynb +++ b/int_assignment.ipynb @@ -1,267 +1,483 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "int_assignment.ipynb", - "provenance": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" + "cells": [ + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "8A5Jw5NR1iEI" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Type of variable 'var': and ID of Var:140718966253648 with value :10.\n" + ] } + ], + "source": [ + "#Declare an int value and store it in a variable. \n", + "\n", + "var=10\n", + "\n", + "#Check the type and print the id of the same.\n", + "print(f\"Type of variable 'var':{type(var)} and ID of 'var':{id(var)} its value :{var}.\")\n" + ] }, - "cells": [ - { - "cell_type": "code", - "metadata": { - "id": "8A5Jw5NR1iEI" - }, - "source": [ - "#Declare an int value and store it in a variable. \n", - "\n", - "\n", - "\n", - "#Check the type and print the id of the same.\n", - "\n" - ], - "execution_count": null, - "outputs": [] - }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "0YU8LFTn1rAX" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "0YU8LFTn1rAX" - }, - "source": [ - "#Take one int value between 0 - 256.\n", - "#Assign it to two different variables.\n", - "#Check the id of both the variables. It should come same. Check why?\n", - "\n", - "\n", - "\n", - "\n", - "#Take one int value either less than -5 or greater than 256.\n", - "#Assign it to two different variables.\n", - "#Check the id of both the variables. It should come different.Check why?\n", - "\n", - "\n" - ], - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "metadata": { - "id": "YzEIG0ZZ1tSK" - }, - "source": [ - "#Arithmatic Operations on integers\n", - "#Take two different intger values.\n", - "#Store them in two different variables.\n", - "#Do below operations on them:-\n", - " #Find sum of both numbers\n", - " #Find differce between them\n", - " #Find the product of both numbers.\n", - " #Find value after dividing first num with second number\n", - " #Find the remainder after dividing first number with second number\n", - " #Find the quotient after dividing first number with second number\n", - " #Find the result of first num to the power of second number." - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "Id of 'var1':140718966256528\n", + "ID of 'var2':140718966256528\n", + "Id of 'var3':1676308288336\n", + "ID of 'var4':1676308288400\n" + ] + } + ], + "source": [ + "#Take one int value between 0 - 256.\n", + "#Assign it to two different variables.\n", + "#Check the id of both the variables. It should come same. Check why?\n", + "var1=100\n", + "var2=100\n", + "\n", + "print(f\"ID of 'var1':{id(var1)}\")\n", + "print(f\"ID of 'var2':{id(var2)}\")\n", + "\n", + "#Take one int value either less than -5 or greater than 256.\n", + "#Assign it to two different variables.\n", + "#Check the id of both the variables. It should come different.Check why?\n", + "\n", + "var3=-8;var4=260\n", + "\n", + "print(f\"ID of 'var3':{id(var3)}\")\n", + "print(f\"ID of 'var4':{id(var4)}\")" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "id": "YzEIG0ZZ1tSK" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "GGM7CdzA1wGn" - }, - "source": [ - "#Comparison Operators on integers\n", - "#Take two different intger values.\n", - "#Store them in two different variables.\n", - "#Do below operations on them:-\n", - " #Compare se two numbers with below operator:-\n", - " #Greater than, '>'\n", - " #Smaller than, '<'\n", - " #Greater than or equal to, '>='\n", - " #Less than or equal to, '<='\n", - "#Observe their output(return type should be boolean)" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "35\n", + "11\n", + "276\n", + "1.92\n", + "11\n", + "1.92\n", + "21914624432020321\n" + ] + } + ], + "source": [ + "#Arithmatic Operations on integers\n", + "#Take two different intger values.\n", + "#Store them in two different variables.\n", + "val1=23 ;val2=12\n", + "#Do below operations on them:-\n", + "#Find sum of both numbers\n", + "print(val1+val2)\n", + "#Find differce between them\n", + "print(val1-val2)\n", + "#Find the product of both numbers.\n", + "print(val1* val2)\n", + "#Find value after dividing first num with second number\n", + "res=round(val1/val2,2)\n", + "print(res)\n", + "#Find the remainder after dividing first number with second number\n", + "print(val1%val2)\n", + "#Find the quotient after dividing first number with second number\n", + "print(round(val1//val2,2))\n", + "#Find the result of first num to the power of second number.\n", + "print(val1**val2)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "id": "GGM7CdzA1wGn" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "9x904sUE1y9t" - }, - "source": [ - "#Equality Operator\n", - "#Take two different intger values.\n", - "#Store them in two different variables.\n", - "#Equuate them using equality operator (==, !=)\n", - "#Observe the output(return type should be boolean)" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "val1 : 48 and val2 : 32\n", + "_________________________\n", + "val1>val2: True\n", + "val1=val2: True\n", + "val1<=val2: False\n" + ] + } + ], + "source": [ + "#Comparison Operators on integers\n", + "\n", + "#Take two different intger values.\n", + "val1= 48;val2=32;\n", + "#Store them in two different variables.\n", + "\n", + "#Do below operations on them:-\n", + " #Compare se two numbers with below operator:-\n", + "print(f\"val1 : {val1} and val2 : {val2}\") \n", + "print(\"_________________________\")\n", + "#Greater than, '>'\n", + "print(\"val1>val2:\",val1>val2)\n", + "#Smaller than, '<'\n", + "print(\"val1='\n", + "print(\"val1>=val2:\",val1>=val2)\n", + "#Less than or equal to, '<='\n", + "print(\"val1<=val2:\",val1<=val2)\n", + "#Observe their output(return type should be boolean)" + ] + }, + { + "cell_type": "code", + "execution_count": 33, + "metadata": { + "id": "9x904sUE1y9t" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "v9-sAvlZZdoi" - }, - "source": [ - "" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "num1:1234 num2:345\n", + "_________________________\n", + "is equal: False\n", + "is not equal: True\n" + ] + } + ], + "source": [ + "#Equality Operator\n", + "\n", + "#Take two different intger values.\n", + "\n", + "#Store them in two different variables.\n", + "num1= 1234 ;num2=345\n", + "#Equuate them using equality operator (==, !=)\n", + "print(f\"num1:{num1} num2:{num2}\")\n", + "print(\"_________________________\")\n", + "#Observe the output(return type should be boolean)\n", + "print(\"is equal: \",num1==num2)\n", + "print(\"is not equal: \",num1!=num2)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "v9-sAvlZZdoi" + }, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 23, + "metadata": { + "id": "JmQFHUwc11S-" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "JmQFHUwc11S-" - }, - "source": [ - "#Logical operators\n", - "#Observe the output of below code\n", - "#Cross check the output manually\n", - "\n", - "print(10 and 20) #----------------------------------------->Output is 20\n", - "print(0 and 20) #----------------------------------------->Output is 0\n", - "print(20 and 0) #----------------------------------------->Output is 0\n", - "print(0 and 0) #----------------------------------------->Output is 0\n", - "\n", - "print(10 or 20) #----------------------------------------->Output is 10\n", - "print(0 or 20) #----------------------------------------->Output is 20\n", - "print(20 or 0) #----------------------------------------->Output is 20\n", - "print(0 or 0) #----------------------------------------->Output is 0\n", - "\n", - "print(not 10) #----------------------------------------->Output is False\n", - "print(not 0) #----------------------------------------->Output is True" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "20\n", + "0\n", + "0\n", + "0\n", + "10\n", + "20\n", + "20\n", + "0\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "#Logical operators\n", + "#Observe the output of below code\n", + "#Cross check the output manually\n", + "\n", + "print(10 and 20) #----------------------------------------->Output is 20\n", + "print(0 and 20) #----------------------------------------->Output is 0\n", + "print(20 and 0) #----------------------------------------->Output is 0\n", + "print(0 and 0) #----------------------------------------->Output is 0\n", + "\n", + "print(10 or 20) #----------------------------------------->Output is 10\n", + "print(0 or 20) #----------------------------------------->Output is 20\n", + "print(20 or 0) #----------------------------------------->Output is 20\n", + "print(0 or 0) #----------------------------------------->Output is 0\n", + "\n", + "print(not 10) #----------------------------------------->Output is False\n", + "print(not 0) #----------------------------------------->Output is True" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": { + "id": "-0tvoulX14Hi" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "-0tvoulX14Hi" - }, - "source": [ - "#Bitwise Operators\n", - "#Do below operations on the values provided below:-\n", - " #Bitwise and(&) -----------------------------------------> 10, 20 -------> Output is 0\n", - " #Bitwise or(|) -----------------------------------------> 10, 20 -------> Output is 30\n", - " #Bitwise(^) -----------------------------------------> 10, 20 -------> Output is 30\n", - " #Bitwise negation(~) ------------------------------------> 10 -------> Output is -11\n", - " #Bitwise left shift ------------------------------------> 10,2 -------> Output is 40\n", - " #Bitwise right shift ------------------------------------> 10,2 -------> Output is 2\n", - "#Cross check the output manually" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "Bitwise and of 10 ,20: 0\n", + "Bitwise or of 10 ,20: 30\n", + "Bitwise and of 10 ,20: 0\n", + "Bitwise ^ of 10 ,20: 30\n", + "Bitwise (~) 10: -11\n", + "Bitwise left shift of 10 : 40\n", + "Bitwise right shift of 10 : 2\n" + ] + } + ], + "source": [ + "#Bitwise Operators\n", + "#Do below operations on the values provided below:-\n", + " #Bitwise and(&) -----------------------------------------> 10, 20 -------> Output is 0\n", + " #Bitwise or(|) -----------------------------------------> 10, 20 -------> Output is 30\n", + " #Bitwise(^) -----------------------------------------> 10, 20 -------> Output is 30\n", + " #Bitwise negation(~) ------------------------------------> 10 -------> Output is -11\n", + " #Bitwise left shift ------------------------------------> 10,2 -------> Output is 40\n", + " #Bitwise right shift ------------------------------------> 10,2 -------> Output is 2\n", + "#Cross check the output manually\n", + "print(\"Bitwise and of 10 ,20:\",10&20)\n", + "print(\"Bitwise or of 10 ,20:\",10|20)\n", + "print(\"Bitwise and of 10 ,20:\",10&20)\n", + "print(\"Bitwise ^ of 10 ,20:\",10^20)\n", + "print(\"Bitwise (~) 10: \",~10)\n", + "print(\"Bitwise left shift of 10 :\",10<<2)\n", + "print(\"Bitwise right shift of 10 :\",10>>2)" + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "metadata": { + "id": "YCcx-Qx016hg" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "YCcx-Qx016hg" - }, - "source": [ - "#What is the output of expression inside print statement. Cross check before running the program.\n", - "a = 10\n", - "b = 10\n", - "print(a is b) #True or False?\n", - "print(a is not b) #True or False?\n", - "\n", - "a = 1000\n", - "b = 1000\n", - "print(a is b) #True or False?\n", - "print(a is not b) #True or False?" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "#What is the output of expression inside print statement. Cross check before running the program.\n", + "a = 10\n", + "b = 10\n", + "print(a is b) #True or False?\n", + "print(a is not b) #True or False?\n", + "\n", + "a = 1000\n", + "b = 1000\n", + "print(a is b) #True or False?\n", + "print(a is not b) #True or False?" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": { + "id": "Un2To3XN1_Il" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "Un2To3XN1_Il" - }, - "source": [ - "#What is the output of expression inside print statement. Cross check before running the program.\n", - "print(10+(10*32)//2**5&20+(~(-10))<<2)" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "20\n" + ] + } + ], + "source": [ + "#What is the output of expression inside print statement. Cross check before running the program.\n", + "print(10+(10*32)//2**5&20+(~(-10))<<2)" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "kGRb5RMd1_1I" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "kGRb5RMd1_1I" - }, - "source": [ - "#Membership operation\n", - "#in, not in are two membership operators and it returns boolean value\n", - "\n", - "print('2' in 'Python2.7.8')\n", - "print(10 in [10,10.20,10+20j,'Python'])\n", - "print(10 in (10,10.20,10+20j,'Python'))\n", - "print(2 in {1,2,3})\n", - "print(3 in {1:100, 2:200, 3:300})\n", - "print(10 in range(20))" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "True\n", + "True\n", + "True\n", + "True\n", + "True\n" + ] + } + ], + "source": [ + "#Membership operation\n", + "#in, not in are two membership operators and it returns boolean value\n", + "\n", + "print('2' in 'Python2.7.8')\n", + "print(10 in [10,10.20,10+20j,'Python'])\n", + "print(10 in (10,10.20,10+20j,'Python'))\n", + "print(2 in {1,2,3})\n", + "print(3 in {1:100, 2:200, 3:300})\n", + "print(10 in range(20))" + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": { + "id": "Es7iSvL92B9W" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "Es7iSvL92B9W" - }, - "source": [ - "#An integer can be represented in binary, octal or hexadecimal form.\n", - "#Declare one binary, one octal and one hexadecimal value and store them in three different variables.\n", - "#Convert 9876 to its binary, octal and hexadecimal equivalent and print their corresponding value." - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "35\n", + "1033\n", + "8457\n", + "binary rep of 9876: 0b10011010010100\n", + "octal rep of 9876: 0o23224\n", + "hex rep of 9876: 0x2694\n" + ] + } + ], + "source": [ + "#An integer can be represented in binary, octal or hexadecimal form.\n", + "#Declare one binary, one octal and one hexadecimal value and store them in three different variables.\n", + "v1 = 0b100011#35\n", + "print(v1)\n", + "v2=0o2011\n", + "print(v2)\n", + "v3=0x2109\n", + "print(v3)\n", + "#Convert 9876 to its binary, octal and hexadecimal equivalent and print their corresponding value.\n", + "print('binary rep of 9876: ',bin(9876))\n", + "print('octal rep of 9876: ',oct(9876))\n", + "print('hex rep of 9876: ',hex(9876))" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "Hm0r03lH2E0i" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "Hm0r03lH2E0i" - }, - "source": [ - "#What will be the outut of following:-\n", - "a = 0b1010000\n", - "print(a)\n", - "\n", - "b = 0o7436\n", - "print(b)\n", - "\n", - "c = 0xfade\n", - "print(c)\n", - "\n", - "print(bin(80))\n", - "\n", - "print(oct(3870))\n", - "\n", - "print(hex(64222))\n", - "\n", - "print(bin(0b1010000))\n", - "\n", - "print(bin(0xfade))\n", - "\n", - "print(oct(0xfade))\n", - "\n", - "print(oct(0o7436))\n", - "\n", - "print(hex(0b1010000))\n", - "\n", - "print(hex(0xfade))" - ], - "execution_count": null, - "outputs": [] + "name": "stdout", + "output_type": "stream", + "text": [ + "80\n", + "3870\n", + "64222\n", + "0b1010000\n", + "0o7436\n", + "0xfade\n", + "0b1010000\n", + "0b1111101011011110\n", + "0o175336\n", + "0o7436\n", + "0x50\n", + "0xfade\n" + ] } - ] -} \ No newline at end of file + ], + "source": [ + "#What will be the outut of following:-\n", + "a = 0b1010000\n", + "print(a)\n", + "\n", + "b = 0o7436\n", + "print(b)\n", + "\n", + "c = 0xfade\n", + "print(c)\n", + "\n", + "print(bin(80))\n", + "\n", + "print(oct(3870))\n", + "\n", + "print(hex(64222))\n", + "\n", + "print(bin(0b1010000))\n", + "\n", + "print(bin(0xfade))\n", + "\n", + "print(oct(0xfade))\n", + "\n", + "print(oct(0o7436))\n", + "\n", + "print(hex(0b1010000))\n", + "\n", + "print(hex(0xfade))" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "name": "int_assignment.ipynb", + "provenance": [] + }, + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +}