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
319 changes: 319 additions & 0 deletions YUVRAJ18/yuvraj float_assignment.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,319 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "dlrMB-Qy2taV"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"10.2\n",
"<class 'float'>\n",
"2266763385328\n"
]
}
],
"source": [
"#Declare a float value and store it in a variable. \n",
"num_f = 10.20\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": 11,
"metadata": {
"id": "IL4fVDHg2wbI"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"numf1:10.3 numf2:20.11\n",
"_______________________\n",
"sum: 30.41\n",
"Difference: -9.809999999999999\n",
"multiplication: 207.133\n",
"division: 0.5121829935355545\n",
"remainder: 10.3\n",
"quotient: 0.5121829935355545\n",
"power: 2.334299563481146e+20\n"
]
}
],
"source": [
"#Arithmatic Operations on float\n",
"#Take two different float values.\n",
"#Store them in two different variables.\n",
"\n",
"numf1=10.3; numf2=20.11\n",
"print(f\"numf1:{numf1} numf2:{numf2}\" )\n",
"print(\"_______________________\")\n",
"#Do below operations on them:-\n",
" #Find sum of both numbers\n",
"print(\"sum: \",numf1+numf2)\n",
" #Find differce between them\n",
"print(\"Difference: \",numf1-numf2)\n",
" #Find the product of both numbers.\n",
"print(\"multiplication: \",numf1*numf2)\n",
"\n",
" #Find value after dividing first num with second number\n",
"print(\"division: \",numf1/numf2)\n",
"\n",
" #Find the remainder after dividing first number with second number\n",
"print(\"remainder: \",numf1%numf2)\n",
" #Find the quotient after dividing first number with second number\n",
"print(\"quotient: \",numf1/numf2)\n",
" #Find the result of first num to the power of second number.\n",
"print(\"power: \",numf1**numf2)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {
"id": "atCFaH6c2492"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"num1: 44.67 num2: 98.55\n",
"__________________________\n",
"> : False\n",
"< : True\n",
">= : False\n",
"<= : True\n"
]
}
],
"source": [
"#Comparison Operators on float\n",
"#Take two different float values.\n",
"#Store them in two different variables.\n",
"num1=44.67 ;num2=98.55;\n",
"print(f\"num1: {num1} num2: {num2}\")\n",
"print(\"__________________________\")\n",
"#Do below operations on them:-\n",
" #Compare these two numbers with below operator:-\n",
" #Greater than, '>'\n",
"print(\"> :\" ,num1>num2)\n",
"\n",
" #Smaller than, '<'\n",
"print(\"< :\", num1<num2)\n",
"\n",
"\n",
" #Greater than or equal to, '>='\n",
"print(\">= :\" ,num1>=num2)\n",
"\n",
"\n",
" #Less than or equal to, '<='\n",
"print(\"<= :\" ,num1<=num2)\n",
"\n",
"\n",
"#Observe their output(return type should be boolean)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {
"id": "agi3U3863A5i"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"n1=12.12 n2=12.12\n",
"___________________\n",
"== : True\n",
"!= : False\n"
]
}
],
"source": [
"#Equality Operator\n",
"#Take two different float values.\n",
"#Store them in two different variables.\n",
"n1=12.12 ;n2=12.12;\n",
"print(f\"n1={n1} n2={n2}\")\n",
"print(\"___________________\")\n",
"#Equuate them using equality operator (==, !=)\n",
"print(\"== : \" ,n1 == n2)\n",
"\n",
"print(\"!= : \" ,n1 != n2)\n",
"#Observe the output(return type should be boolean)"
]
},
{
"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": 22,
"metadata": {
"id": "7YdyRNtk3UZd"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"True\n",
"2266763661680\n",
"2266763661680\n",
"False\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(id(a))\n",
"print(id(b))\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",
"#using 'is' we check whther both the operands refer to same object or not.As 2 seperate variables are created and \n",
"#assigned value (eventhough same) it will return false.\n",
"#if b=a is done then they are refering to same object then result will be true."
]
},
{
"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": 7,
"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"
]
},
{
"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.8.8"
}
},
"nbformat": 4,
"nbformat_minor": 1
}