Update app.py
Browse files
app.py
CHANGED
@@ -12,10 +12,10 @@ def update_progress_bar_color(progress):
|
|
12 |
|
13 |
# Function to demonstrate a for loop with colorful output
|
14 |
def demonstrate_for_loop(n):
|
15 |
-
result = ""
|
16 |
progress_bar = st.progress(0) # Initialize the progress bar
|
17 |
st.markdown('<h3 style="color:#1E90FF;">For Loop Executing...</h3>', unsafe_allow_html=True)
|
18 |
|
|
|
19 |
for i in range(1, n + 1):
|
20 |
color = "teal" if i % 2 == 0 else "orange"
|
21 |
result += f'<span style="color:{color}; font-size:24px; font-weight:bold;">{i} </span>'
|
@@ -23,22 +23,20 @@ def demonstrate_for_loop(n):
|
|
23 |
# Update the progress
|
24 |
progress = i / n
|
25 |
progress_bar.progress(progress)
|
26 |
-
progress_color = update_progress_bar_color(progress)
|
27 |
|
28 |
-
# Display results
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
time.sleep(0.5) # Simulate execution time
|
34 |
|
35 |
# Function to demonstrate a while loop with colorful output
|
36 |
def demonstrate_while_loop(n):
|
37 |
-
result = ""
|
38 |
-
i = 1
|
39 |
progress_bar = st.progress(0) # Initialize the progress bar
|
40 |
st.markdown('<h3 style="color:#1E90FF;">While Loop Executing...</h3>', unsafe_allow_html=True)
|
41 |
|
|
|
|
|
42 |
while i <= n:
|
43 |
color = "teal" if i % 2 == 0 else "orange"
|
44 |
result += f'<span style="color:{color}; font-size:24px; font-weight:bold;">{i} </span>'
|
@@ -46,12 +44,10 @@ def demonstrate_while_loop(n):
|
|
46 |
# Update the progress
|
47 |
progress = i / n
|
48 |
progress_bar.progress(progress)
|
49 |
-
progress_color = update_progress_bar_color(progress)
|
50 |
|
51 |
-
# Display results
|
52 |
-
|
53 |
-
|
54 |
-
f'<strong>While Loop result:</strong> {result}</div>', unsafe_allow_html=True)
|
55 |
|
56 |
time.sleep(0.5) # Simulate execution time
|
57 |
i += 1
|
|
|
12 |
|
13 |
# Function to demonstrate a for loop with colorful output
|
14 |
def demonstrate_for_loop(n):
|
|
|
15 |
progress_bar = st.progress(0) # Initialize the progress bar
|
16 |
st.markdown('<h3 style="color:#1E90FF;">For Loop Executing...</h3>', unsafe_allow_html=True)
|
17 |
|
18 |
+
result = ""
|
19 |
for i in range(1, n + 1):
|
20 |
color = "teal" if i % 2 == 0 else "orange"
|
21 |
result += f'<span style="color:{color}; font-size:24px; font-weight:bold;">{i} </span>'
|
|
|
23 |
# Update the progress
|
24 |
progress = i / n
|
25 |
progress_bar.progress(progress)
|
|
|
26 |
|
27 |
+
# Display results in real-time
|
28 |
+
st.markdown(f'<div style="background-color:#fffacd; padding:20px; border-radius:10px; box-shadow: 0px 4px 12px rgba(0,0,0,0.1);">'
|
29 |
+
f'<strong>For Loop result:</strong> {result}</div>', unsafe_allow_html=True)
|
30 |
+
|
|
|
31 |
time.sleep(0.5) # Simulate execution time
|
32 |
|
33 |
# Function to demonstrate a while loop with colorful output
|
34 |
def demonstrate_while_loop(n):
|
|
|
|
|
35 |
progress_bar = st.progress(0) # Initialize the progress bar
|
36 |
st.markdown('<h3 style="color:#1E90FF;">While Loop Executing...</h3>', unsafe_allow_html=True)
|
37 |
|
38 |
+
result = ""
|
39 |
+
i = 1
|
40 |
while i <= n:
|
41 |
color = "teal" if i % 2 == 0 else "orange"
|
42 |
result += f'<span style="color:{color}; font-size:24px; font-weight:bold;">{i} </span>'
|
|
|
44 |
# Update the progress
|
45 |
progress = i / n
|
46 |
progress_bar.progress(progress)
|
|
|
47 |
|
48 |
+
# Display results in real-time
|
49 |
+
st.markdown(f'<div style="background-color:#fffacd; padding:20px; border-radius:10px; box-shadow: 0px 4px 12px rgba(0,0,0,0.1);">'
|
50 |
+
f'<strong>While Loop result:</strong> {result}</div>', unsafe_allow_html=True)
|
|
|
51 |
|
52 |
time.sleep(0.5) # Simulate execution time
|
53 |
i += 1
|