Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,9 @@
"id": "O262clBmccWy"
},
"source": [
"def max_num_in_list( list ):\n",
" max = list[ 0 ]\n",
" for a in list:\n",
" if a > max:\n",
" max = a\n",
" return max"
"def max_num_in_list( list1 ):\n",
" list1.sort()\n",
" return list1[-1]"
],
"execution_count": 3,
"outputs": []
Expand Down Expand Up @@ -77,17 +74,14 @@
"id": "pZ2dsfE9iK8v"
},
"source": [
"def Sequential_Search(dlist, item):\n",
" pos = 0\n",
" found = False\n",
" \n",
" while pos < len(dlist) and not found:\n",
" if dlist[pos] == item:\n",
" found = True\n",
" else:\n",
" pos = pos + 1\n",
" \n",
" return found, pos"
"def sequential_search(list,item):\n,"
" count=0\n,"
" for i in range(0,len(list)):\n",
" if list[i]==item:\n,"\n",
" print("element found")\n",
" count=count+1\n",
" if count==0:\n",
" print("Element not found")"
],
"execution_count": 8,
"outputs": []
Expand All @@ -103,7 +97,7 @@
}
},
"source": [
"print(Sequential_Search([11,23,58,31,56,77,43,12,65,19],31))"
"sequential_search([11,23,58,31,56,77,43,12,65,19],31)
],
"execution_count": 9,
"outputs": [
Expand Down Expand Up @@ -259,8 +253,8 @@
"source": [
"list1 = [1, 2, 3, 0]\n",
"list2 = ['Red', 'Green', 'Black']\n",
"final_list = list1 + list2\n",
"print(final_list)\n"
"list1.extend(list2)\n",
"print(list2)\n"
],
"execution_count": null,
"outputs": [
Expand Down Expand Up @@ -288,18 +282,20 @@
"id": "Z4l_8ViHhEcQ"
},
"source": [
"def composite(n): \n",
"def composite(num): \n",
"\n",
" factor=0\n",
" for i in range(1,n):\n",
" if n%i==0:\n",
" factor=i\n",
" if factor>1:\n",
" print ('The number is a composite number!')\n",
" elif n==1:\n",
" print ('The number 1 is neither prime nor composite!')\n",
" if num==1:\n",
" print("The number is neither prime nor composite")\n",
" return\n"
" if num==2:\n",
" print("The number is not composite")\n",
" return\n",
" for factor in range(2,int((num/2)+1)):\n",
" if num%factor==0:\n",
" print("The number is not composite")\n",
" return\n",
" else:\n",
" print ('This is not a composite number!')\n",
" print ('The number is not composite!')\n",
"\n"
],
"execution_count": 12,
Expand Down Expand Up @@ -588,9 +584,10 @@
"id": "5_SbE5nFjkiD"
},
"source": [
"def table(number,start,end): \n",
"\tfor i in range (start, end+1): \n",
"\t\tprint (\"%d * %d = %d\" % (number, i, number * i) )"
"def table(num,num1,num2): \n",
"for multi in range(num1,num2+1):\n",
" print(str(num)+" X "+str(multi)+" = "+str(num*multi)),"
"
],
"execution_count": null,
"outputs": []
Expand Down Expand Up @@ -672,4 +669,4 @@
]
}
]
}
}