-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject3.py
More file actions
234 lines (196 loc) Β· 5.99 KB
/
project3.py
File metadata and controls
234 lines (196 loc) Β· 5.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
import streamlit as st
st.set_page_config(page_title="Python Data Types Project", page_icon="π‘", layout="centered")
# Title
st.title("π‘ Project 3: Python Data Types vs Data Types in Other Languages")
st.write("This project explains all data types in Python. It also compares them with data types found in other programming languages like C, C++, Java and JavaScript.")
# ---------------------------
# SECTION 1: What are Data Types?
# ---------------------------
with st.expander("π What are Data Types?"):
st.markdown("""
<div style='background-color:#f0f4ff;padding:15px;border-radius:10px;'>
<h3 style='color:#003399;'>Understanding What Data Types Are</h3>
</div>
""", unsafe_allow_html=True)
st.write("""
A data type tells the computer what kind of value you are storing.
It tells how much memory to use and what operations you can perform.
Example:
- 5 is an integer
- 3.14 is a floating number
- "hello" is a string
""")
# ---------------------------
# SECTION 2: Why Python is Different
# ---------------------------
with st.expander("π¦ Why Python Data Types Are Different"):
st.markdown("""
<div style='background-color:#e9ffe9;padding:15px;border-radius:10px;'>
<h3 style='color:#00802b;'>Why Python Stands Out</h3>
</div>
""", unsafe_allow_html=True)
st.write("""
Python is different from languages like C, C++, and Java.
Here is why:
1. Python is dynamically typed.
You do not write the data type manually.
Python figures it out automatically.
Example in Python:
```
x = 10
y = "Hello"
```
Example in Java:
```
int x = 10;
String y = "Hello";
```
2. Python allows you to change the data type of a variable at any time.
```
x = 10
x = "Now I am a string"
```
3. Python has built-in very high level data types like lists, dictionaries, tuples, sets.
C and Java do not have these built in.
4. Python makes data types easy to use without worrying about memory size.
In C, you must pick `int`, `short`, `long`, `float`, `double`, etc.
Python does this automatically.
""")
# ---------------------------
# SECTION 3: Python Data Types (All of Them)
# ---------------------------
with st.expander("π Python Data Types (Detailed List)"):
st.markdown("""
<div style='background-color:#fff5e6;padding:15px;border-radius:10px;'>
<h3 style='color:#cc6600;'>Python Data Types (Classified)</h3>
</div>
""", unsafe_allow_html=True)
st.subheader("1. Numeric Types")
st.write("""
- **int** β whole numbers
- **float** β decimal values
- **complex** β numbers with imaginary part
Example:
```
a = 5
b = 3.14
c = 2 + 3j
```
""")
st.subheader("2. Text Type")
st.write("""
- **str** β strings or text
Example:
```
name = "Tanush"
```
""")
st.subheader("3. Boolean Type")
st.write("""
- **bool** β True or False
""")
st.subheader("4. Sequence Types")
st.write("""
- **list** β ordered, changeable
- **tuple** β ordered, unchangeable
- **range** β sequence of numbers
Example:
```
my_list = [1, 2, 3]
my_tuple = (4, 5, 6)
numbers = range(1, 10)
```
""")
st.subheader("5. Set Types")
st.write("""
- **set** β unordered, unique values
- **frozenset** β frozen version of set (unchangeable)
""")
st.subheader("6. Mapping Types")
st.write("""
- **dict** β key-value pairs
Example:
```
person = {"name": "Asha", "age": 20}
```
""")
st.subheader("7. Binary Types")
st.write("""
- **bytes**
- **bytearray**
- **memoryview**
""")
# ---------------------------
# SECTION 4: Comparison Table
# ---------------------------
with st.expander("π Python vs Other Languages (Side-by-Side Comparison)"):
st.markdown("""
<div style='background-color:#efffff;padding:15px;border-radius:10px;'>
<h3 style='color:#006666;'>Comparison with Languages Like C, Java, JavaScript</h3>
</div>
""", unsafe_allow_html=True)
st.write("""
### β Python (Dynamic)
- No need to declare type
- Easy to write
- Automatically adjusts size
- High-level types built in
### β Java (Static)
- Must declare data types
- Strict
- No built-in lists or dictionaries like Python
- Uses arrays instead
### β C/C++ (Low-level)
- Must manage memory manually
- Harder for beginners
- No built-in strings or lists
### β JavaScript
- Dynamic like Python
- But fewer built-in complex data types
""")
# ---------------------------
# SECTION 5: Memory & Typing Difference
# ---------------------------
with st.expander("πΎ Memory Management and Typing System"):
st.markdown("""
<div style='background-color:#fce6ff;padding:15px;border-radius:10px;'>
<h3 style='color:#9900cc;'>Memory Differences</h3>
</div>
""", unsafe_allow_html=True)
st.write("""
Python automatically manages memory with a garbage collector.
C and C++ require you to free memory yourself.
Java also has garbage collection but requires type declaration.
Python is dynamic.
C, C++, Java are static.
""")
# ---------------------------
# SECTION 6: Code Examples
# ---------------------------
with st.expander("π§ͺ Code Examples Showing Differences"):
st.subheader("Python Example")
st.code("""
x = 10
x = "hello"
print(x)
""")
st.subheader("C Example")
st.code("""
int x = 10;
x = "hello"; // error
""")
st.subheader("Java Example")
st.code("""
int x = 10;
String y = "hello";
""")
st.subheader("JavaScript Example")
st.code("""
let x = 10;
x = "hello"; // works
""")
# ---------------------------
# FOOTER
# ---------------------------
st.write("---")
st.write("End of Project 3. Thank you for reading!")