diff --git a/Saurabh_float_assignment.ipynb b/Saurabh_float_assignment.ipynb new file mode 100644 index 0000000..b5fd3d1 --- /dev/null +++ b/Saurabh_float_assignment.ipynb @@ -0,0 +1,303 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "dlrMB-Qy2taV" + }, + "outputs": [], + "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" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "IL4fVDHg2wbI" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "12.544532570000001\n", + "-0.7471825700000005\n", + "39.201753901719755\n", + "0.8875716847479774\n", + "5.898675\n", + "0.0\n", + "71114.9966587509\n" + ] + } + ], + "source": [ + "#Arithmatic Operations on float\n", + "#Take two different float values.\n", + "#Store them in two different variables.\n", + "\n", + "first = 5.898675\n", + "second = 6.64585757\n", + "#Do below operations on them:-\n", + " #Find sum of both numbers\n", + "\n", + "print(first + second)\n", + " #Find differce between them\n", + "\n", + "print(first-second)\n", + " #Find the product of both numbers.\n", + "\n", + "print(first*second)\n", + " #Find value after dividing first num with second number\n", + "\n", + "print(first/second)\n", + " #Find the remainder after dividing first number with second number\n", + "\n", + "print(first % second)\n", + " #Find the quotient after dividing first number with second number\n", + "\n", + "print(first // second)\n", + " #Find the result of first num to the power of second number.\n", + "\n", + "print(first ** second)" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": { + "id": "atCFaH6c2492" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n", + "False\n", + "True\n", + "False\n" + ] + } + ], + "source": [ + "#Comparison Operators on float\n", + "#Take two different float values.\n", + "#Store them in two different variables.\n", + "\n", + "one = 4.867678\n", + "two = 2.978899\n", + "#Do below operations on them:-\n", + " #Compare these two numbers with below operator:-\n", + " #Greater than, '>'\n", + "print(one>two)\n", + " #Smaller than, '<'\n", + "print(one='\n", + "print(one>=two)\n", + " #Less than or equal to, '<='\n", + "print(one<=two)\n", + "#Observe their output(return type should be boolean)\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "agi3U3863A5i" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n" + ] + } + ], + "source": [ + "#Equality Operator\n", + "#Take two different float values.\n", + "#Store them in two different variables.\n", + "\n", + "A = 6.98789\n", + "B = 9.64762\n", + "#Equuate them using equality operator (==, !=)\n", + "\n", + "print(A==B)\n", + "print(A!=B)\n", + "#Observe the output(return type should be boolean)\n", + "\n", + "\n", + "\n", + "\n", + "\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "id": "3HLlgaEt3EnJ" + }, + "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": 7, + "metadata": { + "id": "7YdyRNtk3UZd" + }, + "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\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "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": 8, + "metadata": { + "id": "29AVJHpx3YUo" + }, + "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.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" + ] + } + ], + "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.8.8" + } + }, + "nbformat": 4, + "nbformat_minor": 1 +}