tspsram commited on
Commit
f2cc07a
·
verified ·
1 Parent(s): 2d8399d

Update app.py

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