From 07f2886ea5ec5125cae2cbb09969666bedc730f2 Mon Sep 17 00:00:00 2001 From: Yuvraj1897 <87479789+YOUSEE1897@users.noreply.github.com> Date: Mon, 2 Aug 2021 19:41:31 +0530 Subject: [PATCH] Add files via upload --- YUVRAJ18/INT PROGRAM.ipynb | 524 +++++++++++++++++++++++++++++++++++++ 1 file changed, 524 insertions(+) create mode 100644 YUVRAJ18/INT PROGRAM.ipynb diff --git a/YUVRAJ18/INT PROGRAM.ipynb b/YUVRAJ18/INT PROGRAM.ipynb new file mode 100644 index 0000000..2efc724 --- /dev/null +++ b/YUVRAJ18/INT PROGRAM.ipynb @@ -0,0 +1,524 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "8A5Jw5NR1iEI" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n", + "\n", + "2555354376624\n" + ] + } + ], + "source": [ + "#Declare an int value and store it in a variable. \n", + "\n", + "a = 5\n", + "print(a)\n", + "\n", + "#Check the type and print the id of the same.\n", + "\n", + "print(type(a))\n", + "print(id(a))" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "0YU8LFTn1rAX" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2555354568144\n", + "2555354568144\n", + "2555429871120\n", + "2555429871088\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", + "\n", + "a = 100\n", + "b = 100\n", + "print(id(a))\n", + "print(id(b))\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", + "c = -10\n", + "d = -10\n", + "print(id(d))\n", + "print(id(c))" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "YzEIG0ZZ1tSK" + }, + "outputs": [], + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "44\t\tsum\n", + "-20\t\tsubstraction\n", + "384\t\tmultiplication\n", + "0.375\t\tdivision\n", + "12\t\treminder\n", + "0\t\tquotient\n", + "34182189187166852111368841966125056\ta to the power b\n" + ] + } + ], + "source": [ + "a = 12\n", + "b = 32\n", + "print(a+b,'sum',sep='\\t\\t')\n", + "print(a-b,'substraction',sep='\\t\\t')\n", + "print(a*b,'multiplication',sep='\\t\\t')\n", + "print(a/b,'division',sep='\\t\\t')\n", + "print(a%b,'reminder',sep='\\t\\t')\n", + "print(a//b,'quotient',sep='\\t\\t')\n", + "print(a**b,'a to the power b',sep='\\t')" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": { + "id": "GGM7CdzA1wGn" + }, + "outputs": [], + "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)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "False\n", + "False\n", + "True\n" + ] + } + ], + "source": [ + "print(a>b)\n", + "print(a>b)\n", + "print(a>=b)\n", + "print(a<=b)" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "9x904sUE1y9t" + }, + "outputs": [], + "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)" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": { + "id": "v9-sAvlZZdoi" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n" + ] + } + ], + "source": [ + "print(a==b)\n", + "print(a!=b)" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": { + "id": "JmQFHUwc11S-" + }, + "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": 13, + "metadata": { + "id": "-0tvoulX14Hi" + }, + "outputs": [], + "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" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "30\n", + "30\n", + "-11\n", + "40\n", + "2\n" + ] + } + ], + "source": [ + "a = 10\n", + "b = 20\n", + "print(a & b)\n", + "print(a | b)\n", + "print(a ^ b)\n", + "print(~ a)\n", + "print(a << 2)\n", + "print(a >> 2)" + ] + }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0b1010\n", + "0b10100\n" + ] + } + ], + "source": [ + "print(bin(a))\n", + "print(bin(b))" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": {}, + "outputs": [], + "source": [ + "# a & b = 01010 & 10100 = 00000 = 0 in decimal\n", + "# a | b = 01010 | 10100 = 11110 = 30 in decimal\n", + "# a ^ b = 01010 xor 10100 = 11110 = 30 in decimal\n", + "# ~ a = negation of 01010 = returns 1' complement = -(01010 + 1) = -11\n", + "# a << 2 = left shift by 2, 01010 becomes 0101000 = 8 + 32 = 40\n", + "# a >> 2 = shift right by 2, 01010 becomes 00010 = 2 in demical" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "id": "YCcx-Qx016hg" + }, + "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": 12, + "metadata": { + "id": "Un2To3XN1_Il" + }, + "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)\n", + "# 10 + (320//32" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": { + "id": "kGRb5RMd1_1I" + }, + "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": null, + "metadata": { + "id": "Es7iSvL92B9W" + }, + "outputs": [], + "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." + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": { + "id": "Hm0r03lH2E0i" + }, + "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" + ] + } + ], + "source": [ + "#What will be the outut of following:-\n", + "a = 0b1010000\n", + "print(a)\n", + "# 80\n", + "\n", + "b = 0o7436\n", + "print(b)\n", + "# 3870\n", + "\n", + "c = 0xfade\n", + "print(c)\n", + "# 64222\n", + "\n", + "print(bin(80))\n", + "#0b1010000\n", + "\n", + "\n", + "print(oct(3870))\n", + "#0o7436\n", + "\n", + "print(hex(64222))\n", + "# 0xfade\n", + "\n", + "print(bin(0b1010000))\n", + "# 0b1010000\n", + "\n", + "print(bin(0xfade))\n", + "# 0b1111101011011110\n", + "\n", + "print(oct(0xfade))\n", + "# 0o175336\n", + "\n", + "print(oct(0o7436))\n", + "# 0o7436\n", + "\n", + "print(hex(0b1010000))\n", + "# 0x50\n", + "\n", + "print(hex(0xfade))\n", + "#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.9.5" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +}