mathslearn commited on
Commit
6d09466
·
verified ·
1 Parent(s): 2b7310d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +78 -93
app.py CHANGED
@@ -6,104 +6,89 @@ 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
- # 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
  # Input for initial velocity, u
10
+ u = st.number_input("Enter the initial velocity (u) in metres per second:", step=0.1, format="%.1f")
11
 
12
+ # Determine the initial direction
 
13
 
14
+ if u < 0:
15
+ initial_direction = "travelling to the left"
16
+ elif u > 0:
17
+ initial_direction = "travelling to the right"
18
+ else:
19
+ initial_direction = "at rest"
20
 
21
+ # Input for final velocity, v
22
+ v = st.number_input("Enter the final velocity (v) in metres per second:", step=0.1, format="%.1f")
 
 
 
 
 
23
 
24
+ # Determine the final direction
 
 
 
 
 
 
25
 
26
+ if v < 0:
27
+ final_direction = "travelling to the left"
28
+ elif v > 0:
29
+ final_direction = "travelling to the right"
30
+ else:
31
+ final_direction = "at rest"
32
 
33
+ # Display initial and final velocities information
34
+ st.write(f"Initial velocity (u): {u} m/s means object is {initial_direction} with a speed of {abs(u)} m/s.")
35
+ st.write(f"Final velocity (v): {v} m/s means object is {final_direction} with a speed of {abs(v)} m/s.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
+ # Determine and display the motion description based on the conditions
38
+ if u < 0:
39
+ if v == u:
40
+ st.write("u < 0, v = u")
41
+ st.write("Object was initially travelling to the left.")
42
+ st.write("Object continued travelling to the left with constant speed.")
43
+ elif v < u:
44
+ st.write("u < 0, v < u")
45
+ st.write("Object was initially travelling to the left.")
46
+ st.write("Object continued travelling to the left, accelerated and increased its speed.")
47
+ elif v == 0:
48
+ st.write("u < 0, v = 0")
49
+ st.write("Object was initially travelling to the left.")
50
+ st.write("Object continued travelling to the left, decelerated, decreased its speed and stopped.")
51
+ elif v > u and v < 0:
52
+ st.write("u < 0, v > u and v < 0")
53
+ st.write("Object was initially travelling to the left.")
54
+ st.write("Object continued travelling to the left, decelerated and decreased its speed.")
55
+ elif v > u and v > 0:
56
+ st.write("u < 0, v > u and v > 0")
57
+ st.write("Object was initially travelling to the left.")
58
+ st.write("Object continued travelling to the left, decelerated, decreased its speed and stopped.")
59
+ st.write("Object then accelerated and travelled to the right.")
60
+ elif u > 0:
61
+ if v == u:
62
+ st.write("u > 0, v = u")
63
+ st.write("Object was initially travelling to the right.")
64
+ st.write("Object continued travelling to the right with constant speed.")
65
+ elif v > u:
66
+ st.write("u > 0, v > u")
67
+ st.write("Object was initially travelling to the right.")
68
+ st.write("Object continued travelling to the right, accelerated and increased its speed.")
69
+ elif v == 0:
70
+ st.write("u > 0, v = 0")
71
+ st.write("Object was initially travelling to the right.")
72
+ st.write("Object continued travelling to the right, decelerated, decreased its speed and stopped.")
73
+ elif v < u and v > 0:
74
+ st.write("u > 0, v < u and v > 0")
75
+ st.write("Object was initially travelling to the right.")
76
+ st.write("Object continued travelling to the right, decelerated and decreased its speed.")
77
+ elif v < u and v < 0:
78
+ st.write("u > 0, v < u and v < 0")
79
+ st.write("Object was initially travelling to the right.")
80
+ st.write("Object continued travelling to the right, decelerated, decreased its speed and stopped.")
81
+ st.write("Object then accelerated and travelled to the left.")
82
+ elif u == 0:
83
+ if v == u:
84
+ st.write("Object was initially at rest.")
85
+ st.write("u = 0, v = u")
86
+ st.write("Object continued resting.")
87
+ elif v > u:
88
+ st.write("Object was initially at rest.")
89
+ st.write("u = 0, v > u")
90
+ st.write("Object accelerated and increased its speed to travel to the right.")
91
+ elif v < u:
92
+ st.write("Object was initially at rest.")
93
+ st.write("u = 0, v < u and v < 0")
94
+ st.write("Object accelerated and increased its speed to travel to the left.")