Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
254 changes: 254 additions & 0 deletions Saurabh_complex_assignment.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,254 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"id": "JoMbQLjK3uHZ"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"<class 'complex'>\n",
"55227240\n"
]
}
],
"source": [
"#Declare a complex number and store it in a variable. \n",
"\n",
"a= 5+ 6j\n",
"\n",
"#Check the type and print the id of the same.\n",
"print(type(a))\n",
"print(id(a))\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"id": "6N6Ee4BU33jk"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"(7+9j)\n",
"(-3+1j)\n",
"(-10+33j)\n",
"(0.7317073170731708+0.41463414634146345j)\n",
"(38.470898411503946+4.625946953361943j)\n"
]
}
],
"source": [
"#Arithmatic Operations on complex number\n",
"#Take two different complex number.\n",
"#Store them in two different variables.\n",
"\n",
"first = 2+5j\n",
"second = 5+4j\n",
"\n",
"#Do below operations on them:-\n",
"\n",
" #Find sum of both numbers\n",
"\n",
"print(first+second)\n",
" \n",
" #Find differce between them\n",
"\n",
"print(first-second)\n",
" \n",
" #Find the product of both numbers.\n",
" \n",
"print(first*second)\n",
" \n",
" #Find value after dividing first num with second number\n",
" \n",
"print(first/second)\n",
" \n",
" #Find the result of first num to the power of second number.\n",
"\n",
"print(first ** second)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"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",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"id": "4lzPH2sb38KM"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n",
"True\n"
]
}
],
"source": [
"#Equality Operator\n",
"#Take two different complex numbers.\n",
"\n",
"x= 7+9j\n",
"y= 8+4j\n",
"#Store them in two different variables.\n",
"#Equuate them using equality operator (==, !=)\n",
"\n",
"print(x==y)\n",
"print(x!=y)\n",
"#Observe the output(return type should be boolean)\n",
"\n",
"\n",
"\n",
"\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"id": "EDEl19UD3_tr"
},
"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": 10,
"metadata": {
"id": "4ifueKbP4Br1"
},
"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?\n"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {
"id": "TxMbr5jQ4Dwl"
},
"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+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.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
}