From 5294d63f2f7a5d90b43348c7e5d0564f4bd1ad24 Mon Sep 17 00:00:00 2001 From: Abhijeet Pimparkar <87609598+abhipim@users.noreply.github.com> Date: Sun, 1 Aug 2021 23:08:15 +0530 Subject: [PATCH] Add files via upload --- float_assignment.ipynb | 514 ++++++++++++++++++++++++++--------------- 1 file changed, 324 insertions(+), 190 deletions(-) diff --git a/float_assignment.ipynb b/float_assignment.ipynb index ac5d028..ba473bb 100644 --- a/float_assignment.ipynb +++ b/float_assignment.ipynb @@ -1,200 +1,334 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "float_assignment.ipynb", - "provenance": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "dlrMB-Qy2taV" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10.2\n", + "\n", + "1435443941072\n" + ] } + ], + "source": [ + "#Declare a float value and store it in a variable. \n", + "num_f = 10.20\n", + "\n", + "\n", + "#Check the type and print the id of the same.\n", + "print(num_f)\n", + "print(type(num_f))\n", + "print(id(num_f))\n", + "\n" + ] }, - "cells": [ - { - "cell_type": "code", - "metadata": { - "id": "dlrMB-Qy2taV" - }, - "source": [ - "#Declare a float value and store it in a variable. \n", - "num_f = 10.20\n", - "\n", - "\n", - "\n", - "\n", - "#Check the type and print the id of the same.\n", - "print(num_f)\n", - "print(type(num_f))\n", - "print(id(num_f))\n", - "\n" - ], - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "metadata": { - "id": "IL4fVDHg2wbI" - }, - "source": [ - "#Arithmatic Operations on float\n", - "#Take two different float values.\n", - "#Store them in two different variables.\n", - "\n", - "#Do below operations on them:-\n", - " #Find sum of both numbers\n", - "\n", - " #Find differce between them\n", - " #Find the product of both numbers.\n", - "\n", - " #Find value after dividing first num with second number\n", - "\n", - " #Find the remainder after dividing first number with second number\n", - "\n", - " #Find the quotient after dividing first number with second number\n", - "\n", - " #Find the result of first num to the power of second number." - ], - "execution_count": null, - "outputs": [] - }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": { + "id": "IL4fVDHg2wbI" + }, + "outputs": [], + "source": [ + "#Arithmatic Operations on float\n", + "#Take two different float values.\n", + "#Store them in two different variables.\n", + "\n", + "#Do below operations on them:-\n", + " #Find sum of both numbers\n", + "\n", + " #Find differce between them\n", + " #Find the product of both numbers.\n", + "\n", + " #Find value after dividing first num with second number\n", + "\n", + " #Find the remainder after dividing first number with second number\n", + "\n", + " #Find the quotient after dividing first number with second number\n", + "\n", + " #Find the result of first num to the power of second number." + ] + }, + { + "cell_type": "code", + "execution_count": 27, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "atCFaH6c2492" - }, - "source": [ - "#Comparison Operators on float\n", - "#Take two different float values.\n", - "#Store them in two different variables.\n", - "\n", - "#Do below operations on them:-\n", - " #Compare these two numbers with below operator:-\n", - " #Greater than, '>'\n", - "\n", - " #Smaller than, '<'\n", - "\n", - " #Greater than or equal to, '>='\n", - "\n", - " #Less than or equal to, '<='\n", - "\n", - "#Observe their output(return type should be boolean)\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "155.444\t\tsum\n", + "91.2\t\tsubstraction\n", + "3961.44\t\tmultiplication\n", + "3.84\t\tdivision\n", + "26.95\t\treminder\n", + "3.0\t\tquotient\n", + "1.48e+67\ta to the power b\n" + ] + } + ], + "source": [ + "a = 123.321\n", + "b = 32.123\n", + "print(a+b,'sum',sep='\\t\\t')\n", + "print(round(a-b,2),'substraction',sep='\\t\\t')\n", + "print(round(a*b,2),'multiplication',sep='\\t\\t')\n", + "print(round(a/b,2),'division',sep='\\t\\t')\n", + "print(round(a%b,2),'reminder',sep='\\t\\t')\n", + "print(a//b,'quotient',sep='\\t\\t')\n", + "print(round(a**b,-64),'a to the power b',sep='\\t')" + ] + }, + { + "cell_type": "code", + "execution_count": 28, + "metadata": { + "id": "atCFaH6c2492" + }, + "outputs": [], + "source": [ + "#Comparison Operators on float\n", + "#Take two different float values.\n", + "#Store them in two different variables.\n", + "\n", + "#Do below operations on them:-\n", + " #Compare these two numbers with below operator:-\n", + " #Greater than, '>'\n", + "\n", + " #Smaller than, '<'\n", + "\n", + " #Greater than or equal to, '>='\n", + "\n", + " #Less than or equal to, '<='\n", + "\n", + "#Observe their output(return type should be boolean)" + ] + }, + { + "cell_type": "code", + "execution_count": 29, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "agi3U3863A5i" - }, - "source": [ - "#Equality Operator\n", - "#Take two different float values.\n", - "#Store them in two different variables.\n", - "\n", - "#Equuate them using equality operator (==, !=)\n", - "\n", - "#Observe the output(return type should be boolean)\n", - "\n", - "\n", - "\n", - "\n", - "\n", - "\n" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "True\n", + "True\n", + "False\n" + ] + } + ], + "source": [ + "print(a>b)\n", + "print(a>b)\n", + "print(a>=b)\n", + "print(a<=b)" + ] + }, + { + "cell_type": "code", + "execution_count": 30, + "metadata": { + "id": "agi3U3863A5i" + }, + "outputs": [], + "source": [ + "#Equality Operator\n", + "#Take two different float values.\n", + "#Store them in two different variables.\n", + "\n", + "#Equuate them using equality operator (==, !=)\n", + "\n", + "#Observe the output(return type should be boolean)" + ] + }, + { + "cell_type": "code", + "execution_count": 31, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "3HLlgaEt3EnJ" - }, - "source": [ - "#Logical operators\n", - "#Observe the output of below code\n", - "#Cross check the output manually\n", - "\n", - "print(10.20 and 20.30) #both are true and second value taken >Output is 20.3\n", - "print(0.0 and 20.30) #First is false so first value taken->Output is 0.0\n", - "print(20.30 and 0.0) #Goes to till second and second value is false so second is taken>Output is 0.0\n", - "print(0.0 and 0.0) #First is false so first value is taken->Output is 0.0\n", - "\n", - "print(10.20 or 20.30) #First is True so first value is taken>Output is 10.2\n", - "print(0.0 or 20.30) #Goes to till second and second is true second value is taken->Output is 20.3\n", - "print(20.30 or 0.0) #First is True so first value is taken->Output is 20.3\n", - "print(0.0 or 0.0) #Goes to till second and secod is also false and second value is taken>Output is 0.0\n", - "\n", - "print(not 10.20) #-Not of true is false->Output is False\n", - "print(not 0.0) #Not of false is True>Output is True" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n" + ] + } + ], + "source": [ + "print(a==b)\n", + "print(a!=b)" + ] + }, + { + "cell_type": "code", + "execution_count": 34, + "metadata": { + "id": "3HLlgaEt3EnJ" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "7YdyRNtk3UZd" - }, - "source": [ - "#What is the output of expression inside print statement. Cross check before running the program.\n", - "a = 10.20\n", - "b - 10.20\n", - "print(a is b) #True or False? True 10.20<256\n", - "print(a is not b) #True or False? False\n", - "\n", - "\n", - "# Why the Id of float values are different when the same value is assigned to two different variables\n", - "# ex: a = 10.5 b=10.5. but id will be same if I assign the variable having float i.e. a=c then both a anc c's\n", - "# Id are same\n" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "20.3\n", + "0.0\n", + "0.0\n", + "0.0\n", + "10.2\n", + "20.3\n", + "20.3\n", + "0.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.20 and 20.30) #both are true and second value taken >Output is 20.3\n", + "print(0.0 and 20.30) #First is false so first value taken->Output is 0.0\n", + "print(20.30 and 0.0) #Goes to till second and second value is false so second is taken>Output is 0.0\n", + "print(0.0 and 0.0) #First is false so first value is taken->Output is 0.0\n", + "\n", + "print(10.20 or 20.30) #First is True so first value is taken>Output is 10.2\n", + "print(0.0 or 20.30) #Goes to till second and second is true second value is taken->Output is 20.3\n", + "print(20.30 or 0.0) #First is True so first value is taken->Output is 20.3\n", + "print(0.0 or 0.0) #Goes to till second and secod is also false and second value is taken>Output is 0.0\n", + "\n", + "print(not 10.20) #-Not of true is false->Output is False\n", + "print(not 0.0) #Not of false is True>Output is True" + ] + }, + { + "cell_type": "code", + "execution_count": 36, + "metadata": { + "id": "7YdyRNtk3UZd" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "iTvnIMLd3VLW" - }, - "source": [ - "#Bitwise operation is not applicable between instances of float.\n", - "## Why the Id of float values are different when the same value is assigned to two different variables\n", - "## ex: a = 10.5 b=10.5. but id will be same if I assign the variable having float i.e. a=c then both a anc c's\n", - "## Id are same\n", - "#Object reusability concept is not applicable on float values." - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n" + ] + } + ], + "source": [ + "#What is the output of expression inside print statement. Cross check before running the program.\n", + "a = 10.20\n", + "b - 10.20\n", + "print(a is b) #True or False? True 10.20<256\n", + "print(a is not b) #True or False? False\n", + "\n", + "\n", + "# Why the Id of float values are different when the same value is assigned to two different variables\n", + "# ex: a = 10.5 b=10.5. but id will be same if I assign the variable having float i.e. a=c then both a anc c's\n", + "# Id are same" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As I read & observed, for smaller integers and smaller strings, python does memory optimization by using same id every time the number is used. But same is not true for larger integers, string, float or complex numbers etc. \n", + "i.e. object reusability is applicable only for smaller integers and short strings" + ] + }, + { + "cell_type": "code", + "execution_count": 39, + "metadata": { + "id": "iTvnIMLd3VLW" + }, + "outputs": [], + "source": [ + "#Bitwise operation is not applicable between instances of float.\n", + "## Why the Id of float values are different when the same value is assigned to two different variables\n", + "## ex: a = 10.5 b=10.5. but id will be same if I assign the variable having float i.e. a=c then both a anc c's\n", + "## Id are same\n", + "#Object reusability concept is not applicable on float values." + ] + }, + { + "cell_type": "code", + "execution_count": 40, + "metadata": { + "id": "29AVJHpx3YUo" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "29AVJHpx3YUo" - }, - "source": [ - "#Membership operation\n", - "#in, not in are two membership operators and it returns boolean value\n", - "\n", - "print('2.7' in 'Python2.7.8') #True\n", - "print(10.20 in [10,10.20,10+20j,'Python']) #True\n", - "print(10.20 in (10,10.20,10+20j,'Python')) # True\n", - "print(20.30 in {1,20.30,30+40j}) # True\n", - "print(2.3 in {1:100, 2.3:200, 30+40j:300}) # True\n", - "print(10 in range(20)) # True" - ], - "execution_count": null, - "outputs": [] + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "True\n", + "True\n", + "True\n", + "True\n", + "True\n" + ] } - ] -} \ No newline at end of file + ], + "source": [ + "#Membership operation\n", + "#in, not in are two membership operators and it returns boolean value\n", + "\n", + "print('2.7' in 'Python2.7.8') #True\n", + "print(10.20 in [10,10.20,10+20j,'Python']) #True\n", + "print(10.20 in (10,10.20,10+20j,'Python')) # True\n", + "print(20.30 in {1,20.30,30+40j}) # True\n", + "print(2.3 in {1:100, 2.3:200, 30+40j:300}) # True\n", + "print(10 in range(20)) # True" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "colab": { + "name": "float_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 +}