Spaces:
Running
Running
Akshay Agrawal
commited on
Commit
ยท
661b6f9
1
Parent(s):
898d23c
flatten python structure
Browse files- Python/{phase_1/number_operations.py โ 001_numbers.py} +0 -0
- Python/{phase_1/string_manipulation.py โ 002_strings.py} +74 -75
- Python/{phase_1/collections.py โ 003_collections.py} +0 -0
- Python/{phase_2/conditional_logic.py โ 004_conditional_logic.py} +0 -0
- Python/{phase_2/loop_structures.py โ 005_loops.py} +0 -0
- Python/{phase_3/dictionaries.py โ 006_dictionaries.py} +0 -0
- Python/{phase_3/advanced_collections.py โ 007_advanced_collections.py} +0 -0
- Python/{phase_4/function_design.py โ 008_functions.py} +0 -0
- Python/{phase_4/modular_programming.py โ 009_modular_programming.py} +0 -0
- Python/{phase_5/error_management.py โ 010_exceptions.py} +0 -0
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.
|
11 |
app = marimo.App()
|
12 |
|
13 |
|
@@ -21,20 +21,20 @@ def _():
|
|
21 |
def _(mo):
|
22 |
mo.md(
|
23 |
"""
|
24 |
-
#
|
25 |
|
26 |
-
|
27 |
|
28 |
-
##
|
29 |
-
|
30 |
-
ways:
|
31 |
|
32 |
```python
|
33 |
-
|
34 |
-
|
|
|
35 |
```
|
36 |
|
37 |
-
Below is an example
|
38 |
"""
|
39 |
)
|
40 |
return
|
@@ -42,70 +42,69 @@ def _(mo):
|
|
42 |
|
43 |
@app.cell
|
44 |
def _():
|
45 |
-
|
46 |
-
return (
|
47 |
|
48 |
|
49 |
@app.cell(hide_code=True)
|
50 |
def _(mo):
|
51 |
mo.md(
|
52 |
"""
|
53 |
-
##
|
54 |
|
55 |
-
|
56 |
|
57 |
-
|
58 |
-
computed values below change.
|
59 |
"""
|
60 |
)
|
61 |
return
|
62 |
|
63 |
|
64 |
@app.cell
|
65 |
-
def _(
|
66 |
-
|
67 |
return
|
68 |
|
69 |
|
70 |
@app.cell
|
71 |
-
def _(
|
72 |
-
|
73 |
return
|
74 |
|
75 |
|
76 |
@app.cell
|
77 |
-
def _(
|
78 |
-
|
79 |
return
|
80 |
|
81 |
|
82 |
@app.cell
|
83 |
-
def _(
|
84 |
-
|
85 |
return
|
86 |
|
87 |
|
88 |
@app.cell(hide_code=True)
|
89 |
def _(mo):
|
90 |
-
mo.md("""
|
91 |
return
|
92 |
|
93 |
|
94 |
@app.cell
|
95 |
-
def _(
|
96 |
-
|
97 |
return
|
98 |
|
99 |
|
100 |
@app.cell
|
101 |
-
def _(
|
102 |
-
|
103 |
return
|
104 |
|
105 |
|
106 |
@app.cell
|
107 |
-
def _(
|
108 |
-
|
109 |
return
|
110 |
|
111 |
|
@@ -113,12 +112,9 @@ def _(text):
|
|
113 |
def _(mo):
|
114 |
mo.md(
|
115 |
"""
|
116 |
-
##
|
117 |
|
118 |
-
|
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 |
-
|
130 |
-
return (
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
|
133 |
@app.cell
|
134 |
-
def _(
|
135 |
-
|
136 |
return
|
137 |
|
138 |
|
@@ -140,65 +142,62 @@ def _(my_name):
|
|
140 |
def _(mo):
|
141 |
mo.md(
|
142 |
"""
|
143 |
-
##
|
144 |
-
|
145 |
"""
|
146 |
)
|
147 |
return
|
148 |
|
149 |
|
150 |
@app.cell
|
151 |
-
def _(
|
152 |
-
|
153 |
-
|
154 |
-
return (first_letter,)
|
155 |
|
156 |
|
157 |
@app.cell
|
158 |
-
def _(
|
159 |
-
|
160 |
-
|
161 |
-
return (last_letter,)
|
162 |
|
163 |
|
164 |
@app.cell
|
165 |
-
def _(
|
166 |
-
|
167 |
-
|
168 |
-
return (first_three,)
|
169 |
|
170 |
|
171 |
@app.cell
|
172 |
-
def _(
|
173 |
-
|
174 |
-
|
175 |
-
return (last_two,)
|
176 |
|
177 |
|
178 |
@app.cell(hide_code=True)
|
179 |
def _(mo):
|
180 |
mo.md(
|
181 |
"""
|
182 |
-
##
|
183 |
|
184 |
-
|
185 |
|
186 |
```python
|
187 |
-
|
188 |
|
189 |
-
#
|
190 |
-
|
191 |
|
192 |
-
#
|
193 |
-
|
|
|
194 |
|
195 |
-
#
|
196 |
-
|
|
|
197 |
|
198 |
-
#
|
199 |
-
|
200 |
-
|
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 |
-
##
|
212 |
|
213 |
Next Steps:
|
214 |
|
215 |
-
-
|
216 |
|
217 |
-
-
|
218 |
|
219 |
-
-
|
220 |
|
221 |
-
|
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
|