diff --git a/requirements.txt b/requirements.txt index 7633c8ad1..cce10ea1e 100644 Binary files a/requirements.txt and b/requirements.txt differ diff --git a/webpages/__pycache__/code_editor.cpython-312.pyc b/webpages/__pycache__/code_editor.cpython-312.pyc index f6bbf1676..06aa7b6b3 100644 Binary files a/webpages/__pycache__/code_editor.cpython-312.pyc and b/webpages/__pycache__/code_editor.cpython-312.pyc differ diff --git a/webpages/code_editor.py b/webpages/code_editor.py index f8ec6663e..c8a1d440f 100644 --- a/webpages/code_editor.py +++ b/webpages/code_editor.py @@ -2,6 +2,12 @@ import streamlit as st import subprocess from streamlit_ace import st_ace +import re + +# check if user import python module +def analyze_imports(code): + pattern = r'^\s*(from\s+\S+\s+)?import\s+(\S+)(\s+as\s+\S+)?' + return re.findall(pattern, code, re.MULTILINE) def code_editor(height="300px", sample_code = "", editor_label = "",min_lines = 20): @@ -26,6 +32,9 @@ def code_editor(height="300px", sample_code = "", editor_label = "",min_lines = ) + if analyze_imports(content): + st.warning("Code Editor does not support importing packages") + return if content: with open("./webpages/input_code.py", "w") as f: diff --git a/webpages/input_code.py b/webpages/input_code.py index 1d23f8784..5328929cc 100644 --- a/webpages/input_code.py +++ b/webpages/input_code.py @@ -1,12 +1,10 @@ -# Example 3: Demonstrating basic arithmetic operations -a = 10 # Assigns integer 10 to variable 'a' -b = 3 # Assigns integer 3 to variable 'b' -c = 2.5 # Assigns floating-point number 2.5 to variable 'c' +# Example 1 +Age = 24; +if Age >=18: + print('You are an adult') -print('Addition: ', a + b) # Prints the sum of 'a' and 'b' -print('Subtraction: ', a - b) # Prints the result of subtracting 'b' from 'a' -print('Multiplication: ', a * b) # Prints the product of 'a' and 'b' -print('Multiplication: ', a * c) # Prints the product of 'a' and 'c', demonstrating integer-float multiplication -print('Division: ', a / b) # Prints the division of 'a' by 'b', result is a float -print('Floor Division: ', a // b) # Prints the floor division of 'a' by 'b', removing digits after the decimal point -print('Modulus: ', a % b) # Prints the remainder of 'a' divided by 'b' \ No newline at end of file +# Example 2 +has_license = False +if has_license == True: # False == True-> Flase + print('You can drive') +print('False condition, skip the if statement') \ No newline at end of file