mathslearn commited on
Commit
923d8e4
·
verified ·
1 Parent(s): 4484ebb

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +65 -76
app.py CHANGED
@@ -1,103 +1,92 @@
1
- st.title("Self Learn Kinematics")
2
-
3
- if "my_text" not in st.session_state:
4
- st.session_state.my_text = ""
5
-
6
- def submit():
7
- st.session_state.my_text = st.session_state.widget
8
- st.session_state.widget = ""
9
-
10
- st.text_input("Enter text here", key="widget", on_change=submit)
11
-
12
- query = st.session_state.my_text
13
 
14
- st.sidebar.image(logo_url, caption="Practice makes perfect.", use_column_width=True)
15
-
16
- if 'responses' not in st.session_state:
17
- st.session_state['responses'] = []
18
 
19
- if 'requests' not in st.session_state:
20
- st.session_state['requests'] = []
 
21
 
22
- print("If velocity value is positive, object is travelling to the right.")
23
- print("If velocity value is negative, object is travelling in the opposite direction to the left.")
24
 
25
- # Ask for input for initial velocity, u
26
- u = float(input("Enter the initial velocity (u) in metres per second: "))
27
  if u < 0:
28
- d = "travelling to the left"
29
  elif u > 0:
30
- d = "travelling to the right"
31
- elif u == 0:
32
- d = "at rest"
 
 
 
33
 
34
- # Ask for input for final velocity, v
35
- v = float(input("Enter the final velocity (v) in metres per second: "))
36
  if v < 0:
37
- d = "travelling to the left"
38
  elif v > 0:
39
- d = "travelling to the right"
40
- elif v == 0:
41
- d = "at rest"
42
 
43
- # Print the values to confirm
44
- print(f"Initial velocity (u): {u} m/s means object is {d} with a speed of {abs(u)} m/s.")
45
- print(f"Final velocity (v): {v} m/s means object is {d} with a speed of {abs(v)} m/s.")
46
 
 
47
  if u < 0:
48
  if v == u:
49
- print("u < 0, v = u")
50
- print("Object was initially travelling to the left.")
51
- print("Object continued travelling to the left with constant speed.")
52
  elif v < u:
53
- print("u < 0, v < u")
54
- print("Object was initially travelling to the left.")
55
- print("Object continued travelling to the left, accelerated and increased its speed.")
56
  elif v == 0:
57
- print("u < 0, v = 0")
58
- print("Object was initially travelling to the left.")
59
- print("Object continued travelling to the left, decelerated, decreased its speed and stopped.")
60
  elif v > u and v < 0:
61
- print("u < 0, v > u and v < 0")
62
- print("Object was initially travelling to the left.")
63
- print("Object continued travelling to the left, decelerated and decreased its speed.")
64
  elif v > u and v > 0:
65
- print("u < 0, v > u and v > 0")
66
- print("Object was initially travelling to the left.")
67
- print("Object continued travelling to the left, decelerated, decreased its speed and stopped.")
68
- print("Object then accelerated and travelled to the right.")
69
  elif u > 0:
70
  if v == u:
71
- print("u > 0, v = u")
72
- print("Object was initially travelling to the right.")
73
- print("Object continued travelling to the right with constant speed.")
74
  elif v > u:
75
- print("u > 0, v > u")
76
- print("Object was initially travelling to the right.")
77
- print("Object continued travelling to the right, accelerated and increased its speed.")
78
  elif v == 0:
79
- print("u > 0, v = 0")
80
- print("Object was initially travelling to the right.")
81
- print("Object continued travelling to the right, decelerated, decreased its speed and stopped.")
82
  elif v < u and v > 0:
83
- print("u > 0, v < u and v > 0")
84
- print("Object was initially travelling to the right.")
85
- print("Object continued travelling to the right, decelerated and decreased its speed.")
86
  elif v < u and v < 0:
87
- print("u > 0, v < u and v < 0")
88
- print("Object was initially travelling to the right.")
89
- print("Object continued travelling to the right, decelerated, decreased its speed and stopped.")
90
- print("Object then accelerated and travelled to the left.")
91
  elif u == 0:
92
  if v == u:
93
- print("Object was initially at rest.")
94
- print("u = 0, v = u")
95
- print("Object continued resting.")
96
  elif v > u:
97
- print("Object was initially at rest.")
98
- print("u = 0, v > u")
99
- print("Object accelerated and increased its speed to travel to the right.")
100
  elif v < u:
101
- print("Object was initially at rest.")
102
- print("u = 0, v < u and v < 0")
103
- print("Object accelerated and increased its speed to travel to the left.")
 
1
+ import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
2
 
3
+ st.title("Self Learn Kinematics")
 
 
 
4
 
5
+ # Display introduction
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
  if u < 0:
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
+ # Determine the final direction
 
24
  if v < 0:
25
+ final_direction = "travelling to the left"
26
  elif v > 0:
27
+ final_direction = "travelling to the right"
28
+ else:
29
+ final_direction = "at rest"
30
 
31
+ # Display initial and final velocities information
32
+ st.write(f"Initial velocity (u): {u} m/s means object is {initial_direction} with a speed of {abs(u)} m/s.")
33
+ st.write(f"Final velocity (v): {v} m/s means object is {final_direction} with a speed of {abs(v)} m/s.")
34
 
35
+ # Determine and display the motion description based on the conditions
36
  if u < 0:
37
  if v == u:
38
+ st.write("u < 0, v = u")
39
+ st.write("Object was initially travelling to the left.")
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.")