Skip to content

Commit 0043f79

Browse files
committed
Created using Colab
1 parent 94c9244 commit 0043f79

1 file changed

Lines changed: 332 additions & 0 deletions

File tree

maymee/Ex2_datatypes.ipynb

Lines changed: 332 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,332 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {
6+
"id": "view-in-github",
7+
"colab_type": "text"
8+
},
9+
"source": [
10+
"<a href=\"https://colab.research.google.com/github/Maymee614/PythonProgramming/blob/main/maymee/Ex2_datatypes.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"metadata": {
16+
"id": "X_Unw3z9u2-7"
17+
},
18+
"source": [
19+
"Ex 1 : Check the lenght of the string \"My name is python\""
20+
]
21+
},
22+
{
23+
"cell_type": "code",
24+
"execution_count": 2,
25+
"metadata": {
26+
"colab": {
27+
"base_uri": "https://localhost:8080/"
28+
},
29+
"id": "9I4x5QjcTeme",
30+
"outputId": "a41c6a0c-e14c-4df4-aec2-8fb13c59abb9"
31+
},
32+
"outputs": [
33+
{
34+
"output_type": "execute_result",
35+
"data": {
36+
"text/plain": [
37+
"6"
38+
]
39+
},
40+
"metadata": {},
41+
"execution_count": 2
42+
}
43+
],
44+
"source": [
45+
"my_name=\"python\"\n",
46+
"len(my_name)"
47+
]
48+
},
49+
{
50+
"cell_type": "markdown",
51+
"metadata": {
52+
"id": "1AIZGQszTemf"
53+
},
54+
"source": [
55+
"Ex 2: Check the number of times \"python\" (regardless of cases: PYTHON, python, Python\" appears in the paragraph : \"Floating-point values in Python are always done in double precision; hence, Python float types correspond to doubles in a C-like language.\""
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 55,
61+
"metadata": {
62+
"colab": {
63+
"base_uri": "https://localhost:8080/"
64+
},
65+
"id": "R_4NHTt0Temg",
66+
"outputId": "162e2818-c331-4d0b-e945-ae7d7c3ff981"
67+
},
68+
"outputs": [
69+
{
70+
"output_type": "execute_result",
71+
"data": {
72+
"text/plain": [
73+
"2"
74+
]
75+
},
76+
"metadata": {},
77+
"execution_count": 55
78+
}
79+
],
80+
"source": [
81+
"my_str = \"Floating-point values in Python are always done in double precision; hence, Python float types correspond to doubles in a C-like language.\"\n",
82+
"my_str.count(\"Python\")"
83+
]
84+
},
85+
{
86+
"cell_type": "markdown",
87+
"metadata": {
88+
"id": "irUaOorkTemh"
89+
},
90+
"source": [
91+
"Ex 3: Combine two lists : ls1 = [\"apple\", \"banana\", \"cherry\"] and ls2 = [\"apple\", \"banana\", \"cherry\", \"apple\", \"cherry\"]. Print the number of elements in new list."
92+
]
93+
},
94+
{
95+
"cell_type": "code",
96+
"execution_count": 19,
97+
"metadata": {
98+
"colab": {
99+
"base_uri": "https://localhost:8080/"
100+
},
101+
"id": "eYvGC_qWTemh",
102+
"outputId": "b8b645af-c548-4aed-b9c4-ddff08821bd7"
103+
},
104+
"outputs": [
105+
{
106+
"output_type": "stream",
107+
"name": "stdout",
108+
"text": [
109+
"8\n"
110+
]
111+
}
112+
],
113+
"source": [
114+
"ls1 = [\"apple\", \"banana\", \"cherry\"]\n",
115+
"ls2 = [\"apple\", \"banana\", \"cherry\", \"apple\", \"cherry\"]\n",
116+
"combined = ls1 + ls2\n",
117+
"print(len(combined))\n"
118+
]
119+
},
120+
{
121+
"cell_type": "markdown",
122+
"metadata": {
123+
"id": "Zaq7CJZQTemi"
124+
},
125+
"source": [
126+
"| Name | Age |\n",
127+
"| --- | --- |\n",
128+
"| Myo | 32 |\n",
129+
"| Thida | 64 |"
130+
]
131+
},
132+
{
133+
"cell_type": "markdown",
134+
"metadata": {
135+
"id": "MCGMjSdNTemh"
136+
},
137+
"source": [
138+
"Ex 4: Create a dictionary for the following table:"
139+
]
140+
},
141+
{
142+
"cell_type": "markdown",
143+
"metadata": {
144+
"id": "kTaWp8mYTemi"
145+
},
146+
"source": [
147+
"Ex 5: Combine two sets and print the combined set and its length.\n",
148+
"set1 = {\"Name\", \"age\", \"Height\"}\n",
149+
"set2 = {\"Name\", \"status\", \"Education\"}"
150+
]
151+
},
152+
{
153+
"cell_type": "code",
154+
"execution_count": 56,
155+
"metadata": {
156+
"id": "GjJJssxWTemj"
157+
},
158+
"outputs": [],
159+
"source": [
160+
"my_set1 = {\"Name\", \"age\", \"Height\"}\n",
161+
"my_set2 = {\"Name\", \"status\", \"Education\"}\n",
162+
"combined_set = my_set1.add(\"my_set2\")\n",
163+
"\n",
164+
"\n",
165+
"\n"
166+
]
167+
},
168+
{
169+
"cell_type": "markdown",
170+
"metadata": {
171+
"id": "-iy-DIICTemj"
172+
},
173+
"source": [
174+
"Ex 6: Write a program that asks the user to enter a string. The program should create a new string called new_string from the user's string such that the second character is changed to an asterisk and three exclamation points are attached to the end of the string. Finally, print new_string."
175+
]
176+
},
177+
{
178+
"cell_type": "code",
179+
"execution_count": 88,
180+
"metadata": {
181+
"colab": {
182+
"base_uri": "https://localhost:8080/"
183+
},
184+
"id": "K7yzdfu-Temj",
185+
"outputId": "a097d6b5-f81e-47e9-ca88-44fe29c08657"
186+
},
187+
"outputs": [
188+
{
189+
"output_type": "stream",
190+
"name": "stdout",
191+
"text": [
192+
"Modified string: M*yme!!!\n"
193+
]
194+
}
195+
],
196+
"source": [
197+
"user_string = \"Mayme\"\n",
198+
"len(user_string)\n",
199+
"\n",
200+
"new_string = user_string[0] + '*' + user_string[2:]\n",
201+
"new_string += '!!!'\n",
202+
"\n",
203+
"print(\"Modified string:\", new_string)\n"
204+
]
205+
},
206+
{
207+
"cell_type": "markdown",
208+
"metadata": {
209+
"id": "Van08VcdTemk"
210+
},
211+
"source": [
212+
"Ex 7: Write a program that converts the given string 's' to lowercase, removes all Punctuation marks such as period, hyphen, and commas from 's', and prints the resulting string."
213+
]
214+
},
215+
{
216+
"cell_type": "code",
217+
"execution_count": 102,
218+
"metadata": {
219+
"colab": {
220+
"base_uri": "https://localhost:8080/"
221+
},
222+
"id": "crXxyIfyTemk",
223+
"outputId": "d8f98871-5e71-4ff0-82f0-3a2997ae1dc0"
224+
},
225+
"outputs": [
226+
{
227+
"output_type": "stream",
228+
"name": "stdout",
229+
"text": [
230+
"floating-point values in python are always done in double precision; hence, python float types correspond to doubles in a c-like language\n",
231+
"floatingpoint values in python are always done in double precision; hence, python float types correspond to doubles in a clike language\n",
232+
"floatingpoint values in python are always done in double precision; hence python float types correspond to doubles in a clike language\n"
233+
]
234+
}
235+
],
236+
"source": [
237+
"s = \"Floating-point values in Python are always done in double precision; hence, Python float types correspond to doubles in a C-like language.\"\n",
238+
"s = s.lower()\n",
239+
"for char in ['.', '-', ',']:\n",
240+
" s = s.replace(char, '')\n",
241+
" print(s)\n",
242+
"\n",
243+
"\n"
244+
]
245+
},
246+
{
247+
"cell_type": "markdown",
248+
"metadata": {
249+
"id": "5kAI7D8HTemk"
250+
},
251+
"source": [
252+
"Ex 8: L1 and L2 should be identical. Write a program that finds the missing number in L2."
253+
]
254+
},
255+
{
256+
"cell_type": "code",
257+
"execution_count": 105,
258+
"metadata": {
259+
"id": "y_YJB3MsTemk"
260+
},
261+
"outputs": [],
262+
"source": [
263+
"from random import randint\n",
264+
"L1 = list(range(1,101))\n",
265+
"L2 = L1.copy()\n",
266+
"L2.remove(randint(1,101))\n",
267+
"\n"
268+
]
269+
},
270+
{
271+
"cell_type": "markdown",
272+
"metadata": {
273+
"id": "MLCtlSaxTeml"
274+
},
275+
"source": [
276+
"Ex 9: Write a program to copy the ls1 = [\"apple\", \"banana\", \"cherry\"] to a new list. Add the element \"blueberry\" to the new list, but keep the original list the same."
277+
]
278+
},
279+
{
280+
"cell_type": "code",
281+
"execution_count": 109,
282+
"metadata": {
283+
"colab": {
284+
"base_uri": "https://localhost:8080/"
285+
},
286+
"id": "MaXIzJC8Teml",
287+
"outputId": "a6810c84-161d-4187-f041-368496e690b4"
288+
},
289+
"outputs": [
290+
{
291+
"output_type": "stream",
292+
"name": "stdout",
293+
"text": [
294+
"New list: ['apple', 'banana', 'cherry', 'blueberry']\n"
295+
]
296+
}
297+
],
298+
"source": [
299+
"ls1 = [\"apple\", \"banana\", \"cherry\"]\n",
300+
"new_list = ls1.copy()\n",
301+
"new_list.append(\"blueberry\")\n",
302+
"print(\"New list:\", new_list)"
303+
]
304+
}
305+
],
306+
"metadata": {
307+
"colab": {
308+
"name": "Ex_2_datatypes.ipynb",
309+
"provenance": [],
310+
"include_colab_link": true
311+
},
312+
"kernelspec": {
313+
"display_name": "Python 3",
314+
"language": "python",
315+
"name": "python3"
316+
},
317+
"language_info": {
318+
"codemirror_mode": {
319+
"name": "ipython",
320+
"version": 3
321+
},
322+
"file_extension": ".py",
323+
"mimetype": "text/x-python",
324+
"name": "python",
325+
"nbconvert_exporter": "python",
326+
"pygments_lexer": "ipython3",
327+
"version": "3.12.1"
328+
}
329+
},
330+
"nbformat": 4,
331+
"nbformat_minor": 0
332+
}

0 commit comments

Comments
 (0)