From bf51b528290dfb878191c41c835e6e753fa38701 Mon Sep 17 00:00:00 2001 From: Abhijeet Pimparkar <87609598+abhipim@users.noreply.github.com> Date: Sun, 1 Aug 2021 23:04:44 +0530 Subject: [PATCH] Add files via upload --- Complex_Assignement.ipynb | 392 ++++++++++++++++++++++++-------------- 1 file changed, 254 insertions(+), 138 deletions(-) diff --git a/Complex_Assignement.ipynb b/Complex_Assignement.ipynb index df66580..39aee38 100644 --- a/Complex_Assignement.ipynb +++ b/Complex_Assignement.ipynb @@ -1,147 +1,263 @@ { - "nbformat": 4, - "nbformat_minor": 0, - "metadata": { - "colab": { - "name": "Complex_Assignement.ipynb", - "provenance": [] - }, - "kernelspec": { - "name": "python3", - "display_name": "Python 3" + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "id": "JoMbQLjK3uHZ" + }, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "1836235062544\n" + ] } + ], + "source": [ + "#Declare a complex number and store it in a variable. \n", + "a = 10 + 11j\n", + "\n", + "#Check the type and print the id of the same.\n", + "\n", + "print(type(a))\n", + "print(id(a))\n" + ] }, - "cells": [ - { - "cell_type": "code", - "metadata": { - "id": "JoMbQLjK3uHZ" - }, - "source": [ - "#Declare a complex number and store it in a variable. \n", - "\n", - "\n", - "\n", - "#Check the type and print the id of the same.\n", - "\n", - "\n" - ], - "execution_count": null, - "outputs": [] - }, - { - "cell_type": "code", - "metadata": { - "id": "6N6Ee4BU33jk" - }, - "source": [ - "#Arithmatic Operations on complex number\n", - "#Take two different complex number.\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 result of first num to the power of second number.\n", - "\n", - "\n" - ], - "execution_count": null, - "outputs": [] - }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "id": "6N6Ee4BU33jk" + }, + "outputs": [], + "source": [ + "#Arithmatic Operations on complex number\n", + "#Take two different complex number.\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 result of first num to the power of second number." + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [], + "source": [ + "a = 10 + 11j\n", + "b = 12 - 5j" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "xhkdg7LD352y" - }, - "source": [ - "#Comparison Operation not applicable between instance of complex values\n", - "#Object reusability concept is not applicable on complex numebr\n", - "\n" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "(22+6j)\n", + "(-2+16j)\n", + "(175+82j)\n", + "(0.3846153846153846+1.0769230769230769j)\n", + "(-7025821002987773+2628820204353065j)\n" + ] + } + ], + "source": [ + "print(a+b)\n", + "print(a-b)\n", + "print(a*b)\n", + "print(a/b)\n", + "print(a**b)" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "id": "xhkdg7LD352y" + }, + "outputs": [], + "source": [ + "#Comparison Operation not applicable between instance of complex values\n", + "#Object reusability concept is not applicable on complex numebr\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "id": "4lzPH2sb38KM" + }, + "outputs": [], + "source": [ + "#Equality Operator\n", + "#Take two different complex numbers.\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": 12, + "metadata": {}, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "4lzPH2sb38KM" - }, - "source": [ - "#Equality Operator\n", - "#Take two different complex numbers.\n", - "#Store them in two different variables.\n", - "#Equuate them using equality operator (==, !=)\n", - "#Observe the output(return type should be boolean)\n", - "\n", - "\n", - "\n", - "\n", - "\n" - ], - "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": 13, + "metadata": { + "id": "EDEl19UD3_tr", + "scrolled": true + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "EDEl19UD3_tr" - }, - "source": [ - "#Logical operators\n", - "#Observe the output of below code\n", - "#Cross check the output manually\n", - "\n", - "print(10+20j and 20+30j) #20+30j #----------------------------------------->Output is 20+30j\n", - "print(0+0j and 20+30j) #0+0j #----------------------------------------->Output is 0j\n", - "print(20+30j and 0+0j) #0+0j #----------------------------------------->Output is 0j\n", - "print(0+0j and 0+0j) #0+0j #----------------------------------------->Output is 0j\n", - "\n", - "print(10+20j or 20+30j) #10+20j #----------------------------------------->Output is 10+20j\n", - "print(0+0j or 20+30j) #20+30j #----------------------------------------->Output is 20+30j\n", - "print(20+30j or 0+0j) #20+30j #----------------------------------------->Output is 20+30j\n", - "print(0+0j or 0+0j) #0+0j #----------------------------------------->Output is 0j\n", - "\n", - "print(not 10+20j) #False #----------------------------------------->Output is False\n", - "print(not 0+0j) #True #----------------------------------------->Output is True" - ], - "execution_count": null, - "outputs": [] - }, + "name": "stdout", + "output_type": "stream", + "text": [ + "(20+30j)\n", + "0j\n", + "0j\n", + "0j\n", + "(10+20j)\n", + "(20+30j)\n", + "(20+30j)\n", + "0j\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+20j and 20+30j) #20+30j #----------------------------------------->Output is 20+30j\n", + "print(0+0j and 20+30j) #0+0j #----------------------------------------->Output is 0j\n", + "print(20+30j and 0+0j) #0+0j #----------------------------------------->Output is 0j\n", + "print(0+0j and 0+0j) #0+0j #----------------------------------------->Output is 0j\n", + "\n", + "print(10+20j or 20+30j) #10+20j #----------------------------------------->Output is 10+20j\n", + "print(0+0j or 20+30j) #20+30j #----------------------------------------->Output is 20+30j\n", + "print(20+30j or 0+0j) #20+30j #----------------------------------------->Output is 20+30j\n", + "print(0+0j or 0+0j) #0+0j #----------------------------------------->Output is 0j\n", + "\n", + "print(not 10+20j) #False #----------------------------------------->Output is False\n", + "print(not 0+0j) #True #----------------------------------------->Output is True" + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": { + "id": "4ifueKbP4Br1" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "4ifueKbP4Br1" - }, - "source": [ - "#What is the output of expression inside print statement. Cross check before running the program.\n", - "a = 10+20j\n", - "b = 10+20j\n", - "print(a is b) #False #True or False?\n", - "print(a is not b) #True #True or False?\n" - ], - "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+20j\n", + "b = 10+20j\n", + "print(a is b) #False #True or False?\n", + "print(a is not b) #True #True or False?" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "So 'is' operator checks for the id's of the arguments passed and returns the results based on that\n", + "Interestingly, for complex numbers, unlike integers, python doesn't do memory optimization by pointing both a and b to same memory address although their values are same." + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": { + "id": "TxMbr5jQ4Dwl" + }, + "outputs": [ { - "cell_type": "code", - "metadata": { - "id": "TxMbr5jQ4Dwl" - }, - "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+20j in [10,10.20,10+20j,'Python']) #True\n", - "print(10+20j in (10,10.20,10+20j,'Python')) #True\n", - "print(30+40j in {1,20.30,30+40j}) #True\n", - "print(30+40j 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+20j in [10,10.20,10+20j,'Python']) #True\n", + "print(10+20j in (10,10.20,10+20j,'Python')) #True\n", + "print(30+40j in {1,20.30,30+40j}) #True\n", + "print(30+40j in {1:100, 2.3:200, 30+40j:300}) #True\n", + "print(10 in range(20)) #True" + ] + } + ], + "metadata": { + "colab": { + "name": "Complex_Assignement.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 +}