diff --git a/lab-python-data-structures.ipynb b/lab-python-data-structures.ipynb index 8ba652c..8d0e40f 100644 --- a/lab-python-data-structures.ipynb +++ b/lab-python-data-structures.ipynb @@ -57,13 +57,70 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 31, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdin", + "output_type": "stream", + "text": [ + "Enter the grade of student: 5\n", + "Enter the grade of student: 5\n", + "Enter the grade of student: 5\n", + "Enter the grade of student: 5\n", + "Enter the grade of student: 5\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "text": [ + "25\n", + "3\n", + "score 5 occured 3times\n" + ] + } + ], "source": [ - "# Your code here" + "grade=[]\n", + "for i in range(5):\n", + " grade.append(int(input(\"Enter the grade of student: \")))\n", + "print(f\"{sum(grade)}\") \n", + "new_list=[]\n", + "\n", + "number=[0,2,4]\n", + "for i in number:\n", + " new_list.append(grade[i])\n", + " \n", + "list_2=sorted(new_list)\n", + "list_2\n", + "print(f\"{len(list_2)}\")\n", + "\n", + "count=0\n", + "for j in list_2:\n", + " if j==5:\n", + " count+=1\n", + "print(f\"score 5 occured {count}times\")\n" ] }, + { + "cell_type": "code", + "execution_count": 26, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[4, 5, 5, 5]" + ] + }, + "execution_count": 26, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [] + }, { "cell_type": "markdown", "metadata": {}, @@ -95,11 +152,41 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 63, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "apple\n", + "lemon\n", + "['apple', 'banana', 'mango', 'orange', 'lemon']\n", + "('apple', 'grape', 'mango', 'orange', 'lemon', 'apple', 'grape', 'mango', 'mango', 'orange', 'lemon')\n", + "11\n" + ] + } + ], "source": [ - "# Your code here" + "fruits=(\"apple\", \"grape\", \"mango\", \"orange\", \"lemon\")\n", + "print(f\"{fruits[0]}\")\n", + "print(f\"{fruits[-1]}\")\n", + "fruits_2=list(fruits)\n", + "fruits_2[1]=\"banana\"\n", + "print(f\"{fruits_2}\")\n", + "fruits_3=tuple(fruits_2)\n", + "#concatenate new tuple\n", + "new=(\"apple\", \"grape\", \"mango\", \"orange\", \"lemon\",\"pear\", \"guava\")\n", + "new_2=fruits + new\n", + "final_inventory=new_2 + fruits\n", + "final_inventory\n", + "\n", + "#split tuple\n", + "inventory_split1=final_inventory[:3] \n", + "inventory_split2= final_inventory[-3:]\n", + "Inventory=fruits+inventory_split1+inventory_split2\n", + "print(f\"{Inventory}\")\n", + "print(f\"{len(Inventory)}\")" ] }, { @@ -136,7 +223,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 71, "metadata": {}, "outputs": [], "source": [ @@ -163,11 +250,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 106, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'', 'g', 'd', 'i', 'a', 'I', 'T', 'B', 'n', 'u', 'f', 'e', 'm', 's', 'y', 'A', 'k', 'r', 'c', 't', 'v', 'l', 'F', 'o', 'w', 'h', 'p', 'S'}\n", + "{'', 'd', 'g', 'i', 'a', 'I', 'T', 'B', 'n', 'e', 'f', 'u', 'm', 's', 'y', 'k', 'r', 't', 'v', 'l', 'q', 'F', 'b', 'o', 'w', 'h', 'S'}\n", + "set()\n" + ] + } + ], "source": [ - "# Your code here" + "import string\n", + "all_punc=string.punctuation\n", + "translator=str.maketrans('', '', all_punc)\n", + "set1 = set(poem.translate(translator))\n", + "set2=set(new_poem.translate(translator))\n", + "\n", + "characters_to_strip = string.whitespace + \"’\"\n", + "cleaned_set1 = {i.strip(characters_to_strip) for i in set1}\n", + "cleaned_set2 = {i.strip(characters_to_strip) for i in set2}\n", + "\n", + "print(f\"{cleaned_set1}\")\n", + "print(f\"{cleaned_set2}\")\n", + "set1_alone=cleaned_set1-cleaned_set2\n", + "set2_alone=cleaned_set2-cleaned_set1\n", + "set1_alone\n", + "set2_alone\n", + "\n", + "#unique words\n", + "unique_words=set1_alone.intersection(set2_alone)\n", + "print(f\"{unique_words}\")" ] }, { @@ -193,7 +309,7 @@ }, { "cell_type": "code", - "execution_count": 51, + "execution_count": 115, "metadata": {}, "outputs": [], "source": [ @@ -202,11 +318,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 122, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'Alice': {'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90},\n", + " 'Bob': {'Physics': 75,\n", + " 'Math': 85,\n", + " 'Chemistry': 60,\n", + " 'Philosophy': 90,\n", + " 'philosohy': 100,\n", + " 'Philosohy': 100}}" + ] + }, + "execution_count": 122, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ - "# Your code here" + "for i in grades:\n", + " if grades[\"Bob\"][\"Philosohy\"]==90:\n", + " [\"Bob\"][\"Philosohy\"]=100\n", + "grades" ] }, { @@ -239,14 +375,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 131, "metadata": {}, - "outputs": [], + "outputs": [ + { + "data": { + "text/plain": [ + "{'Physics': 75, 'Math': 85, 'Chemistry': 60, 'Philosophy': 90}" + ] + }, + "execution_count": 131, + "metadata": {}, + "output_type": "execute_result" + } + ], "source": [ "keys = ['Physics', 'Math', 'Chemistry', 'Philosophy']\n", "values = [75, 85, 60,90]\n", - "\n", - "# Your code here" + "a=list(zip(keys,values))\n", + "dict_a=dict(a)\n", + "dict_a" ] }, { @@ -275,11 +423,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 150, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Chemistry\n" + ] + } + ], "source": [ - "# Your code here" + "all_values=dict_a.values()\n", + "for key,value in dict_a.items():\n", + " if min(all_values)==value:\n", + " print(key)\n", + " \n", + " " ] } ], @@ -299,7 +460,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.13" + "version": "3.12.7" } }, "nbformat": 4,