Akshay Agrawal commited on
Commit
661b6f9
ยท
1 Parent(s): 898d23c

flatten python structure

Browse files
Python/{phase_1/number_operations.py โ†’ 001_numbers.py} RENAMED
File without changes
Python/{phase_1/string_manipulation.py โ†’ 002_strings.py} RENAMED
@@ -7,7 +7,7 @@
7
 
8
  import marimo
9
 
10
- __generated_with = "0.10.12"
11
  app = marimo.App()
12
 
13
 
@@ -21,20 +21,20 @@ def _():
21
  def _(mo):
22
  mo.md(
23
  """
24
- # ๐ŸŽญ Strings
25
 
26
- Dive into the world of Python strings โ€” where text comes to life!
27
 
28
- ## Creating strings
29
- In Python, strings are containers for text. You can create them in two simple
30
- ways:
31
 
32
  ```python
33
- greeting = "Hello, Python!" # using double quotes
34
- name = 'Alice' # using single quotes
 
35
  ```
36
 
37
- Below is an example string.
38
  """
39
  )
40
  return
@@ -42,70 +42,69 @@ def _(mo):
42
 
43
  @app.cell
44
  def _():
45
- text = "Python is amazing"
46
- return (text,)
47
 
48
 
49
  @app.cell(hide_code=True)
50
  def _(mo):
51
  mo.md(
52
  """
53
- ## Essential string operations
54
 
55
- Here are some methods for working with strings.
56
 
57
- Tip: Try changing the value of `text` above, and watch how the
58
- computed values below change.
59
  """
60
  )
61
  return
62
 
63
 
64
  @app.cell
65
- def _(text):
66
- len(text)
67
  return
68
 
69
 
70
  @app.cell
71
- def _(text):
72
- text.upper()
73
  return
74
 
75
 
76
  @app.cell
77
- def _(text):
78
- text.lower()
79
  return
80
 
81
 
82
  @app.cell
83
- def _(text):
84
- text.title()
85
  return
86
 
87
 
88
  @app.cell(hide_code=True)
89
  def _(mo):
90
- mo.md("""Use string methods and the `in` operator to find things in strings.""")
91
  return
92
 
93
 
94
  @app.cell
95
- def _(text):
96
- text.find('is')
97
  return
98
 
99
 
100
  @app.cell
101
- def _(text):
102
- "Python" in text
103
  return
104
 
105
 
106
  @app.cell
107
- def _(text):
108
- "Javascript" in text
109
  return
110
 
111
 
@@ -113,12 +112,9 @@ def _(text):
113
  def _(mo):
114
  mo.md(
115
  """
116
- ## Inserting values in strings
117
 
118
- Modern Python uses f-strings to insert values into strings. For example,
119
- check out how the next cell greets you (and notice the `f''''`)!
120
-
121
- Try changing the value of `my_name`, and watch how the greeting changes.
122
  """
123
  )
124
  return
@@ -126,13 +122,19 @@ def _(mo):
126
 
127
  @app.cell
128
  def _():
129
- my_name = ''
130
- return (my_name,)
 
 
 
 
 
 
131
 
132
 
133
  @app.cell
134
- def _(my_name):
135
- f"Hello, {my_name}!"
136
  return
137
 
138
 
@@ -140,65 +142,62 @@ def _(my_name):
140
  def _(mo):
141
  mo.md(
142
  """
143
- ## Working with Parts of Strings
144
- You can access any part of a string using its position (index):
145
  """
146
  )
147
  return
148
 
149
 
150
  @app.cell
151
- def _(text):
152
- first_letter = text[0]
153
- first_letter
154
- return (first_letter,)
155
 
156
 
157
  @app.cell
158
- def _(text):
159
- last_letter = text[-1]
160
- last_letter
161
- return (last_letter,)
162
 
163
 
164
  @app.cell
165
- def _(text):
166
- first_three = text[0:3]
167
- first_three
168
- return (first_three,)
169
 
170
 
171
  @app.cell
172
- def _(text):
173
- last_two = text[-2:]
174
- last_two
175
- return (last_two,)
176
 
177
 
178
  @app.cell(hide_code=True)
179
  def _(mo):
180
  mo.md(
181
  """
182
- ## Other helpful string methods
183
 
184
- Finally, here are some other helpful string methods. Feel free to try them out on your own strings!
185
 
186
  ```python
187
- sentence = " python is fun "
188
 
189
- # Remove extra spaces
190
- print(sentence.strip()) # "python is fun"
191
 
192
- # Split into a list of words
193
- print(sentence.split()) # ['python', 'is', 'fun']
 
194
 
195
- # Replace words
196
- print(sentence.replace('fun', 'awesome'))
 
197
 
198
- # Check what kind of text you have
199
- print("123".isdigit()) # True - only numbers?
200
- print("abc".isalpha()) # True - only letters?
201
- print("Python3".isalnum()) # True - letters or numbers?
202
  ```
203
  """
204
  )
@@ -208,17 +207,17 @@ def _(mo):
208
  @app.cell(hide_code=True)
209
  def _(mo):
210
  callout_text = mo.md("""
211
- ## Your String Journey Begins!
212
 
213
  Next Steps:
214
 
215
- - Try combining different string methods
216
 
217
- - Practice with f-strings
218
 
219
- - Experiment with string slicing
220
 
221
- You're doing great! ๐Ÿโœจ
222
  """)
223
 
224
  mo.callout(callout_text, kind="success")
 
7
 
8
  import marimo
9
 
10
+ __generated_with = "0.10.14"
11
  app = marimo.App()
12
 
13
 
 
21
  def _(mo):
22
  mo.md(
23
  """
24
+ # ๐Ÿ”ข Numbers in Python
25
 
26
+ Let's explore how Python handles numbers and mathematical operations!
27
 
28
+ ## Number Types
29
+ Python has several types of numbers:
 
30
 
31
  ```python
32
+ integer = 42 # whole numbers (int)
33
+ decimal = 3.14 # floating-point numbers (float)
34
+ complex_num = 2 + 3j # complex numbers
35
  ```
36
 
37
+ Below is an example number we'll use to explore operations.
38
  """
39
  )
40
  return
 
42
 
43
  @app.cell
44
  def _():
45
+ number = 42
46
+ return (number,)
47
 
48
 
49
  @app.cell(hide_code=True)
50
  def _(mo):
51
  mo.md(
52
  """
53
+ ## Basic Mathematical Operations
54
 
55
+ Python supports all standard mathematical operations.
56
 
57
+ Try changing the value of `number` above and watch how the results change.
 
58
  """
59
  )
60
  return
61
 
62
 
63
  @app.cell
64
+ def _(number):
65
+ number + 10 # Addition
66
  return
67
 
68
 
69
  @app.cell
70
+ def _(number):
71
+ number - 5 # Subtraction
72
  return
73
 
74
 
75
  @app.cell
76
+ def _(number):
77
+ number * 3 # Multiplication
78
  return
79
 
80
 
81
  @app.cell
82
+ def _(number):
83
+ number / 2 # Division (always returns float)
84
  return
85
 
86
 
87
  @app.cell(hide_code=True)
88
  def _(mo):
89
+ mo.md("""Python also has special division operators and power operations.""")
90
  return
91
 
92
 
93
  @app.cell
94
+ def _(number):
95
+ number // 5 # Floor division (rounds down)
96
  return
97
 
98
 
99
  @app.cell
100
+ def _(number):
101
+ number % 5 # Modulus (remainder)
102
  return
103
 
104
 
105
  @app.cell
106
+ def _(number):
107
+ number ** 2 # Exponentiation
108
  return
109
 
110
 
 
112
  def _(mo):
113
  mo.md(
114
  """
115
+ ## Type Conversion
116
 
117
+ You can convert between different number types. Try changing these values!
 
 
 
118
  """
119
  )
120
  return
 
122
 
123
  @app.cell
124
  def _():
125
+ decimal_number = 3.14
126
+ return (decimal_number,)
127
+
128
+
129
+ @app.cell
130
+ def _(decimal_number):
131
+ int(decimal_number) # Convert to integer (truncates decimal part)
132
+ return
133
 
134
 
135
  @app.cell
136
+ def _(number):
137
+ float(number) # Convert to float
138
  return
139
 
140
 
 
142
  def _(mo):
143
  mo.md(
144
  """
145
+ ## Built-in Math Functions
146
+ Python provides many useful built-in functions for working with numbers:
147
  """
148
  )
149
  return
150
 
151
 
152
  @app.cell
153
+ def _(number):
154
+ abs(-number) # Absolute value
155
+ return
 
156
 
157
 
158
  @app.cell
159
+ def _():
160
+ round(3.14159, 2) # Round to 2 decimal places
161
+ return
 
162
 
163
 
164
  @app.cell
165
+ def _():
166
+ max(1, 5, 3, 7, 2) # Find maximum value
167
+ return
 
168
 
169
 
170
  @app.cell
171
+ def _():
172
+ min(1, 5, 3, 7, 2) # Find minimum value
173
+ return
 
174
 
175
 
176
  @app.cell(hide_code=True)
177
  def _(mo):
178
  mo.md(
179
  """
180
+ ## Advanced Math Operations
181
 
182
+ For more complex mathematical operations, Python's `math` module is your friend:
183
 
184
  ```python
185
+ import math
186
 
187
+ # Square root
188
+ math.sqrt(16) # 4.0
189
 
190
+ # Trigonometry
191
+ math.sin(math.pi/2) # 1.0
192
+ math.cos(0) # 1.0
193
 
194
+ # Constants
195
+ math.pi # 3.141592653589793
196
+ math.e # 2.718281828459045
197
 
198
+ # Logarithms
199
+ math.log10(100) # 2.0
200
+ math.log(math.e) # 1.0
 
201
  ```
202
  """
203
  )
 
207
  @app.cell(hide_code=True)
208
  def _(mo):
209
  callout_text = mo.md("""
210
+ ## Master the Numbers!
211
 
212
  Next Steps:
213
 
214
+ - Practice different mathematical operations
215
 
216
+ - Experiment with type conversions
217
 
218
+ - Try out the math module functions
219
 
220
+ Keep calculating! ๐Ÿงฎโœจ
221
  """)
222
 
223
  mo.callout(callout_text, kind="success")
Python/{phase_1/collections.py โ†’ 003_collections.py} RENAMED
File without changes
Python/{phase_2/conditional_logic.py โ†’ 004_conditional_logic.py} RENAMED
File without changes
Python/{phase_2/loop_structures.py โ†’ 005_loops.py} RENAMED
File without changes
Python/{phase_3/dictionaries.py โ†’ 006_dictionaries.py} RENAMED
File without changes
Python/{phase_3/advanced_collections.py โ†’ 007_advanced_collections.py} RENAMED
File without changes
Python/{phase_4/function_design.py โ†’ 008_functions.py} RENAMED
File without changes
Python/{phase_4/modular_programming.py โ†’ 009_modular_programming.py} RENAMED
File without changes
Python/{phase_5/error_management.py โ†’ 010_exceptions.py} RENAMED
File without changes