Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -6,87 +6,104 @@ st.title("Self Learn Kinematics")
|
|
6 |
st.write("If velocity value is positive, the object is travelling to the right.")
|
7 |
st.write("If velocity value is negative, the object is travelling in the opposite direction to the left.")
|
8 |
|
9 |
-
#
|
10 |
-
u
|
|
|
|
|
|
|
11 |
|
12 |
-
#
|
13 |
-
|
14 |
-
initial_direction = "travelling to the left"
|
15 |
-
elif u > 0:
|
16 |
-
initial_direction = "travelling to the right"
|
17 |
-
else:
|
18 |
-
initial_direction = "at rest"
|
19 |
|
20 |
# Input for final velocity, v
|
21 |
-
v = st.number_input("Enter the final velocity (v) in metres per second:", step=0.1, format="%.1f")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
22 |
|
23 |
-
#
|
24 |
-
|
25 |
-
final_direction
|
26 |
-
elif v > 0:
|
27 |
-
final_direction = "travelling to the right"
|
28 |
-
else:
|
29 |
-
final_direction = "at rest"
|
30 |
|
31 |
-
#
|
32 |
-
st.
|
33 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
-
#
|
36 |
-
if
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
st.write("Object continued travelling to the left with constant speed.")
|
41 |
-
elif v < u:
|
42 |
-
st.write("u < 0, v < u")
|
43 |
-
st.write("Object was initially travelling to the left.")
|
44 |
-
st.write("Object continued travelling to the left, accelerated and increased its speed.")
|
45 |
-
elif v == 0:
|
46 |
-
st.write("u < 0, v = 0")
|
47 |
-
st.write("Object was initially travelling to the left.")
|
48 |
-
st.write("Object continued travelling to the left, decelerated, decreased its speed and stopped.")
|
49 |
-
elif v > u and v < 0:
|
50 |
-
st.write("u < 0, v > u and v < 0")
|
51 |
-
st.write("Object was initially travelling to the left.")
|
52 |
-
st.write("Object continued travelling to the left, decelerated and decreased its speed.")
|
53 |
-
elif v > u and v > 0:
|
54 |
-
st.write("u < 0, v > u and v > 0")
|
55 |
-
st.write("Object was initially travelling to the left.")
|
56 |
-
st.write("Object continued travelling to the left, decelerated, decreased its speed and stopped.")
|
57 |
-
st.write("Object then accelerated and travelled to the right.")
|
58 |
-
elif u > 0:
|
59 |
-
if v == u:
|
60 |
-
st.write("u > 0, v = u")
|
61 |
-
st.write("Object was initially travelling to the right.")
|
62 |
-
st.write("Object continued travelling to the right with constant speed.")
|
63 |
-
elif v > u:
|
64 |
-
st.write("u > 0, v > u")
|
65 |
-
st.write("Object was initially travelling to the right.")
|
66 |
-
st.write("Object continued travelling to the right, accelerated and increased its speed.")
|
67 |
-
elif v == 0:
|
68 |
-
st.write("u > 0, v = 0")
|
69 |
-
st.write("Object was initially travelling to the right.")
|
70 |
-
st.write("Object continued travelling to the right, decelerated, decreased its speed and stopped.")
|
71 |
-
elif v < u and v > 0:
|
72 |
-
st.write("u > 0, v < u and v > 0")
|
73 |
-
st.write("Object was initially travelling to the right.")
|
74 |
-
st.write("Object continued travelling to the right, decelerated and decreased its speed.")
|
75 |
-
elif v < u and v < 0:
|
76 |
-
st.write("u > 0, v < u and v < 0")
|
77 |
-
st.write("Object was initially travelling to the right.")
|
78 |
-
st.write("Object continued travelling to the right, decelerated, decreased its speed and stopped.")
|
79 |
-
st.write("Object then accelerated and travelled to the left.")
|
80 |
-
elif u == 0:
|
81 |
-
if v == u:
|
82 |
-
st.write("Object was initially at rest.")
|
83 |
-
st.write("u = 0, v = u")
|
84 |
-
st.write("Object continued resting.")
|
85 |
-
elif v > u:
|
86 |
-
st.write("Object was initially at rest.")
|
87 |
-
st.write("u = 0, v > u")
|
88 |
-
st.write("Object accelerated and increased its speed to travel to the right.")
|
89 |
-
elif v < u:
|
90 |
-
st.write("Object was initially at rest.")
|
91 |
-
st.write("u = 0, v < u and v < 0")
|
92 |
-
st.write("Object accelerated and increased its speed to travel to the left.")
|
|
|
6 |
st.write("If velocity value is positive, the object is travelling to the right.")
|
7 |
st.write("If velocity value is negative, the object is travelling in the opposite direction to the left.")
|
8 |
|
9 |
+
# State variables to hold input values and results
|
10 |
+
if 'u' not in st.session_state:
|
11 |
+
st.session_state.u = 0.0
|
12 |
+
if 'v' not in st.session_state:
|
13 |
+
st.session_state.v = 0.0
|
14 |
|
15 |
+
# Input for initial velocity, u
|
16 |
+
u = st.number_input("Enter the initial velocity (u) in metres per second:", value=st.session_state.u, step=0.1, format="%.1f")
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
# Input for final velocity, v
|
19 |
+
v = st.number_input("Enter the final velocity (v) in metres per second:", value=st.session_state.v, step=0.1, format="%.1f")
|
20 |
+
|
21 |
+
# Buttons for submitting and clearing inputs
|
22 |
+
if st.button("Submit"):
|
23 |
+
st.session_state.u = u
|
24 |
+
st.session_state.v = v
|
25 |
+
|
26 |
+
# Determine the initial direction
|
27 |
+
if st.session_state.u < 0:
|
28 |
+
initial_direction = "travelling to the left"
|
29 |
+
elif st.session_state.u > 0:
|
30 |
+
initial_direction = "travelling to the right"
|
31 |
+
else:
|
32 |
+
initial_direction = "at rest"
|
33 |
+
|
34 |
+
# Determine the final direction
|
35 |
+
if st.session_state.v < 0:
|
36 |
+
final_direction = "travelling to the left"
|
37 |
+
elif st.session_state.v > 0:
|
38 |
+
final_direction = "travelling to the right"
|
39 |
+
else:
|
40 |
+
final_direction = "at rest"
|
41 |
|
42 |
+
# Display initial and final velocities information
|
43 |
+
st.write(f"Initial velocity (u): {st.session_state.u} m/s means object is {initial_direction} with a speed of {abs(st.session_state.u)} m/s.")
|
44 |
+
st.write(f"Final velocity (v): {st.session_state.v} m/s means object is {final_direction} with a speed of {abs(st.session_state.v)} m/s.")
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
# Determine and display the motion description based on the conditions
|
47 |
+
if st.session_state.u < 0:
|
48 |
+
if st.session_state.v == st.session_state.u:
|
49 |
+
st.write("u < 0, v = u")
|
50 |
+
st.write("Object was initially travelling to the left.")
|
51 |
+
st.write("Object continued travelling to the left with constant speed.")
|
52 |
+
elif st.session_state.v < st.session_state.u:
|
53 |
+
st.write("u < 0, v < u")
|
54 |
+
st.write("Object was initially travelling to the left.")
|
55 |
+
st.write("Object continued travelling to the left, accelerated and increased its speed.")
|
56 |
+
elif st.session_state.v == 0:
|
57 |
+
st.write("u < 0, v = 0")
|
58 |
+
st.write("Object was initially travelling to the left.")
|
59 |
+
st.write("Object continued travelling to the left, decelerated, decreased its speed and stopped.")
|
60 |
+
elif st.session_state.v > st.session_state.u and st.session_state.v < 0:
|
61 |
+
st.write("u < 0, v > u and v < 0")
|
62 |
+
st.write("Object was initially travelling to the left.")
|
63 |
+
st.write("Object continued travelling to the left, decelerated and decreased its speed.")
|
64 |
+
elif st.session_state.v > st.session_state.u and st.session_state.v > 0:
|
65 |
+
st.write("u < 0, v > u and v > 0")
|
66 |
+
st.write("Object was initially travelling to the left.")
|
67 |
+
st.write("Object continued travelling to the left, decelerated, decreased its speed and stopped.")
|
68 |
+
st.write("Object then accelerated and travelled to the right.")
|
69 |
+
elif st.session_state.u > 0:
|
70 |
+
if st.session_state.v == st.session_state.u:
|
71 |
+
st.write("u > 0, v = u")
|
72 |
+
st.write("Object was initially travelling to the right.")
|
73 |
+
st.write("Object continued travelling to the right with constant speed.")
|
74 |
+
elif st.session_state.v > st.session_state.u:
|
75 |
+
st.write("u > 0, v > u")
|
76 |
+
st.write("Object was initially travelling to the right.")
|
77 |
+
st.write("Object continued travelling to the right, accelerated and increased its speed.")
|
78 |
+
elif st.session_state.v == 0:
|
79 |
+
st.write("u > 0, v = 0")
|
80 |
+
st.write("Object was initially travelling to the right.")
|
81 |
+
st.write("Object continued travelling to the right, decelerated, decreased its speed and stopped.")
|
82 |
+
elif st.session_state.v < st.session_state.u and st.session_state.v > 0:
|
83 |
+
st.write("u > 0, v < u and v > 0")
|
84 |
+
st.write("Object was initially travelling to the right.")
|
85 |
+
st.write("Object continued travelling to the right, decelerated and decreased its speed.")
|
86 |
+
elif st.session_state.v < st.session_state.u and st.session_state.v < 0:
|
87 |
+
st.write("u > 0, v < u and v < 0")
|
88 |
+
st.write("Object was initially travelling to the right.")
|
89 |
+
st.write("Object continued travelling to the right, decelerated, decreased its speed and stopped.")
|
90 |
+
st.write("Object then accelerated and travelled to the left.")
|
91 |
+
elif st.session_state.u == 0:
|
92 |
+
if st.session_state.v == st.session_state.u:
|
93 |
+
st.write("Object was initially at rest.")
|
94 |
+
st.write("u = 0, v = u")
|
95 |
+
st.write("Object continued resting.")
|
96 |
+
elif st.session_state.v > st.session_state.u:
|
97 |
+
st.write("Object was initially at rest.")
|
98 |
+
st.write("u = 0, v > u")
|
99 |
+
st.write("Object accelerated and increased its speed to travel to the right.")
|
100 |
+
elif st.session_state.v < st.session_state.u:
|
101 |
+
st.write("Object was initially at rest.")
|
102 |
+
st.write("u = 0, v < u and v < 0")
|
103 |
+
st.write("Object accelerated and increased its speed to travel to the left.")
|
104 |
|
105 |
+
# Clear button
|
106 |
+
if st.button("Clear"):
|
107 |
+
st.session_state.u = 0.0
|
108 |
+
st.session_state.v = 0.0
|
109 |
+
st.experimental_rerun() # Rerun the script to reset the input fields and clear the output
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|