From 14ed1783f910404a358124ff59fefeb4ed165e3c Mon Sep 17 00:00:00 2001 From: leonhuang Date: Fri, 26 May 2023 14:51:22 -0500 Subject: [PATCH 1/5] Homework2 --- Leon_Submissions/Homework2.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 Leon_Submissions/Homework2.py diff --git a/Leon_Submissions/Homework2.py b/Leon_Submissions/Homework2.py new file mode 100644 index 0000000..e69de29 From 291ba8204648d16d39d374526a7566fda3f346fd Mon Sep 17 00:00:00 2001 From: leonhuang Date: Fri, 26 May 2023 14:58:20 -0500 Subject: [PATCH 2/5] Homework2 --- Leon_Submissions/Homework2.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/Leon_Submissions/Homework2.py b/Leon_Submissions/Homework2.py index e69de29..d49a35d 100644 --- a/Leon_Submissions/Homework2.py +++ b/Leon_Submissions/Homework2.py @@ -0,0 +1,22 @@ +# Question 7: +# 1. Strings in Python are sequences of Unicode characters, while bytes +# are sequences of raw binary data. +# 2. Strings in Python are immutable, bytes objects are mutable +# 3. Strings in Python are encoded using a specific character encoding, +# bytes objects do not have an inherent encoding and represent raw binary +# data. +import sys + +string_example = "Hello" +bytes_example = b"Hello" + +string_size = sys.getsizeof(string_example) +bytes_size = sys.getsizeof(bytes_example) + +print("Size of string:", string_size) +print("Size of bytes:", bytes_size) + +# Emojis are represented using Unicode characters, which require more +# bytes to store compared to ASCII characters. Therefore, if you have +# a string that contains emojis, its size will be larger than a string +# without emojis. \ No newline at end of file From 081471fa5d7f45367866dd34145219748cb1bd1c Mon Sep 17 00:00:00 2001 From: leonhuang Date: Fri, 26 May 2023 15:14:12 -0500 Subject: [PATCH 3/5] Homework2 --- Leon_Submissions/Homework2.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Leon_Submissions/Homework2.py b/Leon_Submissions/Homework2.py index d49a35d..302b335 100644 --- a/Leon_Submissions/Homework2.py +++ b/Leon_Submissions/Homework2.py @@ -19,4 +19,12 @@ print("Size of bytes:", bytes_size) # Emojis are represented using Unicode characters, which require more # bytes to store compared to ASCII characters. Therefore, if you have # a string that contains emojis, its size will be larger than a string -# without emojis. \ No newline at end of file +# without emojis. + +def print_string_as_numbers(input_string): + for char in input_string: + print(ord(char), end=' ') + +# Example usage +input_string = "Hello, World!" +print_string_as_numbers(input_string) From 74f95278324ed4529385591b78000666752c371a Mon Sep 17 00:00:00 2001 From: cheezedoodle2 Date: Wed, 19 Apr 2023 17:08:42 -0700 Subject: [PATCH 4/5] Updated launch configurations --- .vscode/launch.json | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.vscode/launch.json b/.vscode/launch.json index 5a7d733..0fcaa89 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -7,6 +7,13 @@ "program": "simulation/SimulationRunner.py", "justMyCode": true, "args": "./HotdogSimulation.py" + }, + { + "name": "Python: File", + "type": "python", + "request": "launch", + "program": "${file}", + "justMyCode": true } ] } From 5efb942978f96660c7c8c870a7fa6d2300cf7a0a Mon Sep 17 00:00:00 2001 From: "scott.liu" Date: Wed, 31 May 2023 03:15:55 -0700 Subject: [PATCH 5/5] This is HW3 for May30 --- Scott_Submissions/HW3.py | 63 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 Scott_Submissions/HW3.py diff --git a/Scott_Submissions/HW3.py b/Scott_Submissions/HW3.py new file mode 100644 index 0000000..2a6a163 --- /dev/null +++ b/Scott_Submissions/HW3.py @@ -0,0 +1,63 @@ +# 1. Why does ord("😀") give a different number than 0xf09f9880, which is what the hexdump of the same character yields? +# +# The ord() function returns the Unicode code point of a character as an integer, which is 128512 for the smiley face. +# However, the hexdump command, returns the UTF-8 encoding of character. +# The hexadecimal representation of 128512 is 0x1F600. +# The UTF-8 encoding of the "😀" character is represented by the sequence of bytes F0 9F 98 80 in hexadecimal. +# UTF-8 is one of the encoding schemes used to represent Unicode characters as binary data. +# +# +# 8. Hypothetical Situation: If the dataframe is not formatted or cleaned, while the column storing the tomoto sales data isn't named exactly same as 'Tomato_Sales' +# It will raise a KeyError instead. +# +# +# 9. The solution of the hypothetical situation from my question 8: + +def read_tomato_sales(file_name): + data = pd.read_csv(file_name) + if not pd.api.types.is_numeric_dtype(data["Tomato_Sales"]): + raise TypeError("Tomato_Sales column should contain only numeric values") + total_sales = data.iloc[:, -1].sum() # This is the key + print(f"Total tomato sales: {total_sales}") +# read_tomato_sales("tomato_sales_error.csv") + + +# 10. Different human languages can use various character encodings such as UTF-8, UTF-16, or ASCII. +# While using bytes, you can work with raw data without worrying about specific encodings. +# This allows us to avoid encoding-related errors and ensures compatibility across different language texts. + +def encode_decode_data(): + print('-' * 20) + data = input("Enter a sentence using any language: ") + print('-' * 20) + print("The sentence you entered is: {}".format(data)) + print('-' * 20) + encoded_data = data.encode('utf-8') + print("This sentence after encoded is: {}".format(encoded_data)) + print('-' * 20) + byte_length = len(encoded_data) + print("The byte length of this sentence is: {}".format(byte_length)) + print('-' * 20) + decoded_data = encoded_data.decode() + print("This sentence after decoded is: {}".format(decoded_data)) + print('-' * 20) + +if __name__ == "__main__": + run_function = 'function1' + + if run_function == 'function1': + encode_decode_data() + elif run_function == 'function2': + read_tomato_sales(file_name) + + +# 2.5. REPL stands for Read-Eval-Print Loop. +# A REPL is an interactive programming environment that allows you to read input, evaluate expressions or statements, print output, and repeat the process. +# It provides a quick way to experiment with code, test small snippets, and get immediate feedback. +# The Python REPL allows you to interactively enter Python code and see the results immediately without needing to write a full script and execute it separately. + + +# 3. The '_' is a convention that holds the value of the last printed expression or the result of the last evaluated expression. +# The actual type of the "_" variable depends on the value assigned to it. + +