From 3018fd3a0c706c94b02e51faf2f4a371dc4b5997 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B4=94=E8=89=BA=E9=9C=96?= <24063787g@connect.polyu.hk> Date: Thu, 12 Sep 2024 02:58:39 +0000 Subject: [PATCH] add basic python code --- hello.py | 1 + streamlit_test1.py | 21 +++++++++++++++++++++ students.json | 22 ++++++++++++++++++++++ 3 files changed, 44 insertions(+) create mode 100644 hello.py create mode 100644 streamlit_test1.py create mode 100644 students.json diff --git a/hello.py b/hello.py new file mode 100644 index 0000000..e75154b --- /dev/null +++ b/hello.py @@ -0,0 +1 @@ +print("hello world") \ No newline at end of file diff --git a/streamlit_test1.py b/streamlit_test1.py new file mode 100644 index 0000000..23e299a --- /dev/null +++ b/streamlit_test1.py @@ -0,0 +1,21 @@ +import streamlit as st +# Initialize session state for storing past inputs +if 'text_history' not in st.session_state: + st.session_state.text_history = [] +# Create a text input box +text_input = st.text_input("Enter some text:") +# Create a submit button +submit_button = st.button("Submit") +if submit_button: + st.session_state.text_history.append(text_input) + st.write("You've inputted:", text_input) + st.session_state.input_box = "" +# Clear the input box +# Create a clear button +clear_button = st.button("Clear History") +if clear_button: + st.session_state.text_history = [] +# Display the list of past submitted input +st.write("## Past inputs") +for text in st.session_state.text_history: + st.write(text) \ No newline at end of file diff --git a/students.json b/students.json new file mode 100644 index 0000000..4c430f1 --- /dev/null +++ b/students.json @@ -0,0 +1,22 @@ +{ + "students": [ + { + "id": 1, + "name": "Alice", + "age": 20, + "grades": { + "math": 90, + "science": 85 + } + }, + { + "id": 2, + "name": "Bob", + "age": 22, + "grades": { + "math": 75, + "science": 80 + } + } + ] +}