<jupyter_start><jupyter_text>You should see the versions of the libaries installed in your environment. If you are using the local virtual environment set up by `pipenv`, you should see the following:```The version of numpy is: 1.19.5The version of pandas is: 1.1.5The version of scikit-learn is: 0.22.2.post1```If you are running this notebook on Google Colab, your versions might be different.  Variables<jupyter_code>number_1 = 1
number_2 = 2.0
print(number_1)
print(type(number_1))
print(number_2)
print(type(number_2))
string_1 = "hello"
string_2 = "hello world"
print(string_1)
print(type(string_1))
print(string_2)
print(type(string_2))
list_1 = [1, 2, 3]
print(list_1)
print(len(list_1))
list_2 = ["hello", "world", "1", 1]
print(list_2)
print(list_2[2])
dict_1 = {
    "class_number": "MECE2020",
    "class_capacity": 150,
}
print(type(dict_1))
print(dict_1["class_capacity"])<jupyter_output><empty_output><jupyter_text>Operators<jupyter_code>number_1 + number_2
# this will fail
list_1 / number_1
number_1 >= number_2
len(list_2[0]) == len(list_2[1])
(len(list_2[0]) == len(list_2[1])) and False<jupyter_output><empty_output><jupyter_text>Control Structures<jupyter_code>wether_today = "raining"

if wether_today == "raining":
    print("Bring an umbrella!")
elif wether_today == "sunny":
    print("Enjoy the sun!")
else:
    print("What is the wether today?")
for i in range(10):
    print("The number is:", i)
i = 0
while i < 10:
    print("The number is:", i)
    i += 1<jupyter_output><empty_output><jupyter_text>List comprehension<jupyter_code>list_3 = []
for i in range(10):
    list_3.append(i**2)

list_3
list_4 = [i**2 for i in range(10)]
print(list_4)
list_5 = [1.25, -9.45, 10.22, 3.78, -5.92, 1.16]
list_6 = [x if x > 0 else 0 for x in list_5]

list_6<jupyter_output><empty_output><jupyter_text>Function<jupyter_code>def add(number_1: float, number_2: float) -> float:
    """Add two numbers."""
    return number_1 + number_2

add(1, 2)
def square_root(x: float) -> float:
    """Calcuate the square root of the input using Newton's method.
    
    Args:
        x (float): The input number, must be greater or equal to zero.
    
    Returns:
        (float): Sqaure root of the input.
    
    Raises:
        ValueError: If the input number is negative.
    """
    if x < 0:
        raise ValueError("The input number can not be negative.")
    
    def get_next_guess(current_guess: float) -> float:
        """Get next guess using Newton's method."""
        return 0.5 * (current_guess + x / current_guess)
    
    epislon = 1e-5
    current_guess = x
    next_guess = get_next_guess(current_guess)
    
    while abs(current_guess - next_guess) > epislon:
        current_guess = next_guess
        next_guess = get_next_guess(current_guess)
        
    return next_guess
square_root(3)<jupyter_output><empty_output><jupyter_text>Class<jupyter_code>class Person:
    """A simple class."""
    def __init__(self, name: str):
        self.name = name
    
    def say(self, words: str):
        """Say something."""
        print(f"{self.name} says: {words}")
        
    def pat(self, person: Person):
        """Pat another person."""
        print(f"{self.name} pats {person.name}'s shoulder.")
person_1 = Person("<NAME>")
person_1.say("Hello!")
person_2 = Person("<NAME>")
person_2.say("Hello too!")
person_1.pat(person_2)<jupyter_output><empty_output><jupyter_text>Using `pandas`<jupyter_code>data = pd.read_csv("https://raw.githubusercontent.com/changyaochen/MECE4520/master/lectures/lecture_1/iris.csv")
data.head()
data.shape
# some simple data aggregation
data["Species"].value_counts()
data.groupby("Species")["SepalLengthCm"].mean()
# Some simple visualization
plt.scatter(x=data["SepalLengthCm"], y=data["SepalWidthCm"])
plt.xlabel("SepalLengthCm")
plt.ylabel("SepalWidthCm")
plt.tight_layout()
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13884595569294178, 'fraction_numerical': 0.03297269448737764, 'mean_word_length': 4.378116343490305, 'pattern_counts': {'":': 4, '<': 33, '<?xml version=': 0, '>': 37, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '20691', 'license': 'MIT', 'n_tokens_mistral': 1487, 'n_tokens_neox': 1423, 'n_words': 335, 'path': 'lectures/lecture_1/Hello_world.ipynb', 'repo_name': 'changyaochen/MECE4520', 'size': '3886'}