diff --git a/caesar-cipher b/caesar-cipher new file mode 160000 index 0000000..b58750a --- /dev/null +++ b/caesar-cipher @@ -0,0 +1 @@ +Subproject commit b58750abe747375b1f074f9645d253d7b7bba8ca diff --git a/fizzbuzz b/fizzbuzz new file mode 160000 index 0000000..1ff83ae --- /dev/null +++ b/fizzbuzz @@ -0,0 +1 @@ +Subproject commit 1ff83aecf800991a59190535833fc3c2729878bf diff --git a/week_1/w1bonus.ipynb b/week_1/w1bonus.ipynb index b60c114..4e5bd9f 100644 --- a/week_1/w1bonus.ipynb +++ b/week_1/w1bonus.ipynb @@ -71,6 +71,57 @@ "else:\n", " print(\"The quadratic equation has 2 real solutions.\")" ] + }, + { + "cell_type": "code", + "execution_count": 4, + "id": "4079911d", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The quadratic equation has no real solutions.\n" + ] + } + ], + "source": [ + "import math\n", + "\n", + "# Function to determine the number of solutions for a quadratic equation\n", + "def find_solutions(a, b, c):\n", + " discriminant = b**2 - 4 * a * c # Calculate the discriminant\n", + " \n", + " if discriminant > 0:\n", + " # Two distinct real solutions\n", + " x1 = (-b + math.sqrt(discriminant)) / (2 * a)\n", + " x2 = (-b - math.sqrt(discriminant)) / (2 * a)\n", + " return f\"The quadratic equation has two distinct real solutions: x1 = {x1}, x2 = {x2}\"\n", + " elif discriminant == 0:\n", + " # One real solution (repeated root)\n", + " x = -b / (2 * a)\n", + " return f\"The quadratic equation has exactly one real solution: x = {x}\"\n", + " else:\n", + " # No real solutions\n", + " return \"The quadratic equation has no real solutions.\"\n", + "\n", + "# Input from the user\n", + "try:\n", + " a = float(input(\"Enter the coefficient a (must not be 0): \"))\n", + " if a == 0:\n", + " print(\"Coefficient a must not be zero for a quadratic equation.\")\n", + " else:\n", + " b = float(input(\"Enter the coefficient b: \"))\n", + " c = float(input(\"Enter the coefficient c: \"))\n", + "\n", + " # Determine and print the number of solutions\n", + " result = find_solutions(a, b, c)\n", + " print(result)\n", + "\n", + "except ValueError:\n", + " print(\"Please enter valid numerical values for the coefficients.\")\n" + ] } ], "metadata": { @@ -89,9 +140,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/week_1/w1final.ipynb b/week_1/w1final.ipynb index 3a7f22b..f597be8 100644 --- a/week_1/w1final.ipynb +++ b/week_1/w1final.ipynb @@ -38,25 +38,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The triangle is classified as: Acute triangle\n" + ] + } + ], "source": [ - "angle_1 = int(input(\"Please enter the first angle: \"))\n", - "angle_2 = int(input(\"Please enter the second angle: \"))\n", - "angle_3 = int(input(\"Please enter the third angle: \"))\n", + "# Function to classify the triangle based on its angles\n", + "def classify_triangle(angles):\n", + " a, b, c = angles\n", + " \n", + " # Classifying the triangle based on angle measures\n", + " if a == 90 or b == 90 or c == 90:\n", + " return \"Right triangle\"\n", + " elif a < 90 and b < 90 and c < 90:\n", + " return \"Acute triangle\"\n", + " else:\n", + " return \"Obtuse triangle\"\n", + "\n", + "# Function to check if the angles form a valid triangle\n", + "def is_valid_triangle(angles):\n", + " return all(angle > 0 for angle in angles) and sum(angles) == 180\n", "\n", - "if angle_1 <= 0 or angle_2 <= 0 or angle_3 <= 0:\n", - " print(\"Angles smaller than 0 are not valid.\")\n", - "elif angle_1 + angle_2 + angle_3 == 180:\n", - " if angle_1 == 90 or angle_2 == 90 or angle_3 == 90:\n", - " print(\"The triangle is a right triangle.\")\n", - " elif angle_1 > 90 or angle_2 > 90 or angle_3 > 90:\n", - " print(\"The triangle is an obtuse triangle.\")\n", + "# Input from the user\n", + "try:\n", + " angle1 = int(input(\"Enter the first angle in degrees: \"))\n", + " angle2 = int(input(\"Enter the second angle in degrees: \"))\n", + " angle3 = int(input(\"Enter the third angle in degrees: \"))\n", + " \n", + " angles = (angle1, angle2, angle3)\n", + " \n", + " # Check if the angles form a valid triangle\n", + " if is_valid_triangle(angles):\n", + " triangle_type = classify_triangle(angles)\n", + " print(f\"The triangle is classified as: {triangle_type}\")\n", " else:\n", - " print(\"The triangle is an acute triangle.\")\n", - "else:\n", - " print(\"The entered values are not valid.\")\n" + " print(\"The entered angles are not valid. They must be > 0 and their sum must be 180°.\")\n", + "except ValueError:\n", + " print(\"Please enter valid integer values for the angles.\")\n", + "\n" ] } ], @@ -76,9 +102,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/week_1/w1u2.ipynb b/week_1/w1u2.ipynb index 89cb504..94ae12f 100644 --- a/week_1/w1u2.ipynb +++ b/week_1/w1u2.ipynb @@ -463,11 +463,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "id": "f0e63c53", "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Cube Surface Area: 150\n", + "Cube Volume: 125\n", + "Cuboid Surface Area: 94\n", + "Cuboid Volume: 60\n" + ] + } + ], + "source": [ + "# Cube calculations\n", + "a = 5 # Assign a value for the side length of the cube\n", + "\n", + "# Surface area and volume of a cube\n", + "cube_area = 6 * (a ** 2)\n", + "cube_volume = a ** 3\n", + "\n", + "# Output the results for the cube\n", + "print(\"Cube Surface Area:\", cube_area)\n", + "print(\"Cube Volume:\", cube_volume)\n", + "\n", + "# Cuboid calculations\n", + "a = 5 # Side length a\n", + "b = 3 # Side length b\n", + "c = 4 # Side length c\n", + "\n", + "# Surface area and volume of a cuboid\n", + "cuboid_area = 2 * (a * b + b * c + a * c)\n", + "cuboid_volume = a * b * c\n", + "\n", + "# Output the results for the cuboid\n", + "print(\"Cuboid Surface Area:\", cuboid_area)\n", + "print(\"Cuboid Volume:\", cuboid_volume)\n" + ] } ], "metadata": { @@ -489,9 +524,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +} diff --git a/week_1/w1u3.ipynb b/week_1/w1u3.ipynb index e134b3d..e23c19d 100644 --- a/week_1/w1u3.ipynb +++ b/week_1/w1u3.ipynb @@ -110,14 +110,39 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "You entered the following details:\n", + "First Name: amanda\n", + "Last Name: wilson\n", + "Email Address: amanda88715@gmail.com\n" + ] + } + ], + "source": [ + "# Retrieve user input for first name, last name, and email address\n", + "first_name = input(\"Enter your first name: \")\n", + "last_name = input(\"Enter your last name: \")\n", + "email = input(\"Enter your email address: \")\n", + "\n", + "# Output the entered values\n", + "print(\"\\nYou entered the following details:\")\n", + "print(\"First Name:\", first_name)\n", + "print(\"Last Name:\", last_name)\n", + "print(\"Email Address:\", email)\n" + ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "### Exercise 2\n", "\n", @@ -130,10 +155,31 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The sum is 78.0.\n", + "The product is 77.0.\n" + ] + } + ], + "source": [ + "# Accept two numbers from the user\n", + "num1 = float(input(\"Enter the first number: \"))\n", + "num2 = float(input(\"Enter the second number: \"))\n", + "\n", + "# Calculate the sum and product\n", + "sum_of_numbers = num1 + num2\n", + "product_of_numbers = num1 * num2\n", + "\n", + "# Output the results\n", + "print(f\"The sum is {sum_of_numbers}.\")\n", + "print(f\"The product is {product_of_numbers}.\")\n" + ] } ], "metadata": { @@ -156,7 +202,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -166,4 +212,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_1/w1u4.ipynb b/week_1/w1u4.ipynb index 465c1be..bb1ea40 100644 --- a/week_1/w1u4.ipynb +++ b/week_1/w1u4.ipynb @@ -1,512 +1,610 @@ -{ - "cells": [ - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Data Types\n", - "In this unit, the *primitve* data types are discussed. \n", - "## Primitive Data Types\n", - "In Python, as in most other programming languages, each variable and each expression has a *data type*. In the previous Jupyter Notebooks we have already used a number of these *data types*, without explicitly mentioning them. For example, the following expression contains two values, which have the *data type* `Integer`, the result has the same data type, i.e. `Integer`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "1 + 2" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Python distinguishes between *primitive* and *complex* data types. In this Notebook we will introduce the\n", - "different primitive data types. These are shown in the following table:\n", - "\n", - "| Description | Python data type | Example values |\n", - "| ----------------- | ---------------- | -------------- |\n", - "| Integer numbers | `Integer` | 42, 0, -11 |\n", - "| Decimal numbers | `Float` | 2.0, -3.14 |\n", - "| Logical values | `Boolean` | True, False |\n", - "| Character strings | `String` | \"Hello world\" |" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "The built-in Python function\n", - "`type()` ([Python documentation: type](https://docs.python.org/3/library/functions.html#type))\n", - "can be used to determine the data type of an expression. In the following cell, the function `type()` is used to output\n", - "the data type of the values *41*, *-3.14*, *True* and *\"Hello World\"*." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(type(42))\n", - "print(type(-3.14))\n", - "print(type(True))\n", - "\n", - "s = \"Hello World\"\n", - "print(type(s))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "A short explanation of the notation of `print(type(42))`: Here the two functions `print()` and `type()` are nested into\n", - "each other. That means, `type()` receives the 42 as input value. `type()` now generates some output value. This output\n", - "now serves as input to `print()`. The output of the `print()` function is that `` is finally printed below the cell.\n", - "\n", - "Functions can be nested inside each other. They are then called from inside out. The return value of the inner function serves as an input argument for the outer function. It is possible, to have several levels of nesting. However, the statements become less readable and less understandable." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Integer\n", - "The first primitive data type we will discuss in detail is the data type `Integer`. The `Integer` data type is used to\n", - "represent [integers](https://en.wikipedia.org/wiki/Integer). The value range of the data type thus includes the numbers\n", - "..., -3, -2, -1, 0, 1, 2, 3, ... (i.e. $\\mathbb{Z}$)\n", - "\n", - "It is important to note that the range of `Integer` values in Python is only limited by the available internal memory of\n", - "the computer. Thus, calculations with very large numbers can be performed with Python. In the following cell you can see\n", - "some examples for the data type `Integer`. Test some numbers by yourself!" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(type(2))\n", - "print(type(-5))\n", - "\n", - "x = 10000000000000000000000000000000000000\n", - "print(type(x))\n", - "\n", - "x_squared = x * x\n", - "print(x_squared)\n", - "print(type(x_squared))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Float\n", - "In contrast to the data type `Integer`, the data type `Float` is used to represent [floating point\n", - "numbers](https://en.wikipedia.org/wiki/Floating-point_arithmetic). Decimal places are separated by a dot (`.`). As shown\n", - "in the following cell, the data type `Float` also supports the exponential notation. The notation 6.62e-34 represents the\n", - "number $ 6.62 * 10^{-34} $." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(type(0.1))\n", - "print(type(0.0))\n", - "\n", - "h = 6.63e-34 # https://en.wikipedia.org/wiki/Planck_constant\n", - "print(h)\n", - "print(type(h))\n", - "\n", - "g = 1e100 # https://en.wikipedia.org/wiki/Googol\n", - "print(g)\n", - "print(type(g))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Operations\n", - "The following table has already been shown in the unit about variables. Once again take a look from the data type point of view. \n", - "\n", - "| Description | Operator | Example | Result |\n", - "| ---------------- | -------- | -------- | ------------------ |\n", - "| Addition | + | 2 + 3 | 5 |\n", - "| Subtraction | - | 2 - 3 | -1 |\n", - "| Multiplication | * | 2 * 3 | 6 |\n", - "| Division | / | 7 / 3 | 2.3333333333333335 |\n", - "| Integer division | // | 7 // 3 | 2 |\n", - "| Modulo | % | 7 % 3 | 1 |\n", - "| Exponentiation | ** | 2 ** 0.5 | 1.4142135623730951 |\n", - "\n", - "As you can see, most of the operations have two integers as input an lead to the data type integer as output. Only the division `/` returns the data type float. As can be seen in the last example, combinations of integer and float are possible as well. In the given case they result in the data type float." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Exercise\n", - "Test different operations for the data types `Integer` and `Float`. Use the function `type()` to determine the data type\n", - "of a variable.\n", - "\n", - "Which data type is created when an `Integer` value is combined with a `Float` value using an operator? Will operations with `Integer` values always result in an `Integer` value?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "integer_value = 5\n", - "print(type(integer_value))\n", - "\n", - "float_value = 6.78\n", - "print(type(float_value))\n", - "\n", - "combinated_value = integer_value + float_value\n", - "print(\"The combined value's type is:\", type(combinated_value))\n", - "\n", - "# More values for experimentations:\n", - "print(-12345678900000000000.0)\n", - "print(3 / 1)\n", - "print(2e306 * 10)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Accuracy of operations on 'float' values\n", - "Execute the calculations in the following two cells.\n", - "\n", - "Are the calculated results correct? What could be the cause of these results?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a = 0.1\n", - "b = 0.2\n", - "\n", - "sum = a + b\n", - "print(sum)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "root_of_2 = 2**0.5\n", - "\n", - "two = root_of_2**2\n", - "print(two)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "Internally Python represents floating point numbers with a precision of 15 to 16 digits in the binary system\n", - "([IEEE_754](https://de.wikipedia.org/wiki/IEEE_754)). This representation allows to work with both very large and very\n", - "small numbers. However, rounding errors occur in certain cases. Some numbers cannot be represented precisely in the\n", - "binary system (similar to the number $1/3$ in the decimal system).\n", - "\n", - "Some more examples of possible surprises when working with floating point numbers can be found in the\n", - "[Python Documentation](https://docs.python.org/3/tutorial/floatingpoint.html)." - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# More data types\n", - "## Boolean\n", - "Truth values are represented with the `Boolean` data type. The `Boolean` data type can only take two values: `True` or\n", - "`False`.\n", - "\n", - "There is a set of special logical operators for the `Boolean` data type.\n", - "\n", - "| Operator | Explanation | Example |\n", - "| -------- | ----------- | ----------- |\n", - "| not | Negation | not y |\n", - "| and | Logical AND | x and y |\n", - "| or | Logical OR | a or b or c |" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Exercise\n", - "In the following cell you will find some examples for the use of `Boolean` values. What happens when you combine a\n", - "`Boolean` value with an `Integer` value? What happens when you combine a `Boolean` value with a `Float` value? What\n", - "operators can you use for this? Of which data type is the result?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(False and False)\n", - "print(not False)\n", - "\n", - "a = True\n", - "b = False\n", - "\n", - "print(\"True and True: \", True and True)\n", - "print(\"a and b: \", a and b)\n", - "print(\"a or b: \", a or b)\n", - "\n", - "print(\"Complex logical expression: \", a and (b or (True and False)))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## String\n", - "To process character strings, the `String` data type is used. Strictly speaking `String` is not a primitive data type, but\n", - "a [sequence data type](https://docs.python.org/3/library/stdtypes.html#typesseq). Since strings happen to occur very\n", - "often in simple programs, the data type `String` will be introduced nevertheless.\n", - "\n", - "In Python, `Strings` can be created with either single or double quotes. There are subtle differences between the two\n", - "variations, which will not be discussed further at this point. We will prefer to use double quotes (`\"`) when working\n", - "with `Strings`.\n", - "\n", - "In the following cell you can see, that it is possible to use the `+` operator not only on integers (and floats) but as well on strings. Moreover, it is possible to multiply a string with an interger. What happens, if you multiply a string with a float?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "print(type(\"Hello World\"))\n", - "\n", - "a = \"Hello\"\n", - "b = \"World\"\n", - "\n", - "print(a, b)\n", - "print(a + b)\n", - "\n", - "print(3 * a)" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### String methods\n", - "There are a number of [methods](https://docs.python.org/3/library/string.html). in Python to process `Strings`.\n", - "\n", - "A small selection of these methods is shown below:\n", - "* `.lower()`: changes all upper case letters to lower case\n", - "* `.upper()`: changes all lowercase letters to uppercase\n", - "* `.replace()`: is used to replace a given sequence within a `String` with another one" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Exercise\n", - "Test different operations for `Strings`.\n", - "What happens when you try to add a `string` and an `integer`?\n", - "Also use the above methods to manipulate `Strings`." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a = \"Ramones\"\n", - "print(a.upper())\n", - "\n", - "print(\"hitchhiker\".replace(\"hi\", \"ma\"))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "#### Exercise\n", - "Ask the user to input two numbers (hint: use the function `input()`). Add up those numbers and print the result.\n", - "\n", - "Which problem occurs? Of which data type are the read-in values?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "a = input(\"Please insert a number A: \")\n", - "\n", - "# Please add your code in the following lines\n", - "\n", - "b = " - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "# Conversion\n", - "Operations on `Strings` sometimes lead to unexpected results. The attempt to add a `String` and an `Integer` leads to an\n", - "error message. The addition of two `Strings` causes both strings to be concatenated.\n", - "\n", - "This is a common problem when working with user input. The data type of the input is always `String`. This may have to be\n", - "converted to a different data type before it can be used. For the conversion between the different data types, Python\n", - "provides a number of [built-in functions](https://docs.python.org/3/library/functions.html):\n", - "\n", - "| Function | Explanation | Example |\n", - "| -------- | -------------------------------------------------------- | -------------- |\n", - "| int() | Converts the passed parameter to the data type `Integer` | int(\"10\") |\n", - "| float() | Converts the given parameter to the data type `float` | float(\"3.14\") |\n", - "| bool() | Converts the given parameter to the data type `Boolean` | bool(\"Hello \") |\n", - "| str() | Converts the given parameter to the data type `String` | str(True) |" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Exercise\n", - "Perform some conversions between the different data types. Analyze which data type and which value the result of the\n", - "conversion has. What happens when you concatenate different conversions?" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "s = \"Hello\"\n", - "i = 2019\n", - "print(s + str(i))\n", - "\n", - "print(bool(0))\n", - "\n", - "print(int(bool(3)))\n", - "\n", - "bool(\" \")" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "## Converting and the function `input()`\n", - "As already mentioned, the result of the `input()` function is always a `String`. If you need another data type, you must\n", - "convert the input data at first. The necessary procedure is shown in the following cells." - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "age = input(\"Please insert your age: \")\n", - "age = int(age)\n", - "print(age)\n", - "print(type(age))" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "# Alternatively it is also possible to nest these functions\n", - "age = int(input(\"Please insert your Age: \"))\n", - "print(type(age))" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Exercise\n", - "Create a new version of the cuboid program that reads length, width and height via the input function.\n", - "\n", - "**Notes:**\n", - "- In the function `print()` you can output several parameters. These must be separated by commas.\n", - " Example: `print(a, b, c)`\n", - "- In the function `print()` you can also pass `Strings` directly as parameters. Example: `print(\"The result is:\")`" - ] - }, - { - "cell_type": "markdown", - "metadata": {}, - "source": [ - "### Exercise 2\n", - "\n", - "Use the type() function to assign the type of the variable to `amount_us_presidencies`, then print it.\n" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "amount_us_presidencies = 46\n", - "answer = #your function\n", - "print(answer)" - ] - } - ], - "metadata": { - "file_extension": ".py", - "interpreter": { - "hash": "ae5a99a2531053e9be9d669b7bfc08eaacd0186491e01eb4522a2d385742a1d5" - }, - "kernelspec": { - "display_name": "Python 3", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.7.7" - }, - "mimetype": "text/x-python", - "name": "python", - "npconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": 3 - }, - "nbformat": 4, - "nbformat_minor": 2 -} \ No newline at end of file +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Data Types\n", + "In this unit, the *primitve* data types are discussed. \n", + "## Primitive Data Types\n", + "In Python, as in most other programming languages, each variable and each expression has a *data type*. In the previous Jupyter Notebooks we have already used a number of these *data types*, without explicitly mentioning them. For example, the following expression contains two values, which have the *data type* `Integer`, the result has the same data type, i.e. `Integer`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "1 + 2" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Python distinguishes between *primitive* and *complex* data types. In this Notebook we will introduce the\n", + "different primitive data types. These are shown in the following table:\n", + "\n", + "| Description | Python data type | Example values |\n", + "| ----------------- | ---------------- | -------------- |\n", + "| Integer numbers | `Integer` | 42, 0, -11 |\n", + "| Decimal numbers | `Float` | 2.0, -3.14 |\n", + "| Logical values | `Boolean` | True, False |\n", + "| Character strings | `String` | \"Hello world\" |" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "The built-in Python function\n", + "`type()` ([Python documentation: type](https://docs.python.org/3/library/functions.html#type))\n", + "can be used to determine the data type of an expression. In the following cell, the function `type()` is used to output\n", + "the data type of the values *41*, *-3.14*, *True* and *\"Hello World\"*." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(type(42))\n", + "print(type(-3.14))\n", + "print(type(True))\n", + "\n", + "s = \"Hello World\"\n", + "print(type(s))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "A short explanation of the notation of `print(type(42))`: Here the two functions `print()` and `type()` are nested into\n", + "each other. That means, `type()` receives the 42 as input value. `type()` now generates some output value. This output\n", + "now serves as input to `print()`. The output of the `print()` function is that `` is finally printed below the cell.\n", + "\n", + "Functions can be nested inside each other. They are then called from inside out. The return value of the inner function serves as an input argument for the outer function. It is possible, to have several levels of nesting. However, the statements become less readable and less understandable." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Integer\n", + "The first primitive data type we will discuss in detail is the data type `Integer`. The `Integer` data type is used to\n", + "represent [integers](https://en.wikipedia.org/wiki/Integer). The value range of the data type thus includes the numbers\n", + "..., -3, -2, -1, 0, 1, 2, 3, ... (i.e. $\\mathbb{Z}$)\n", + "\n", + "It is important to note that the range of `Integer` values in Python is only limited by the available internal memory of\n", + "the computer. Thus, calculations with very large numbers can be performed with Python. In the following cell you can see\n", + "some examples for the data type `Integer`. Test some numbers by yourself!" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(type(2))\n", + "print(type(-5))\n", + "\n", + "x = 10000000000000000000000000000000000000\n", + "print(type(x))\n", + "\n", + "x_squared = x * x\n", + "print(x_squared)\n", + "print(type(x_squared))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Float\n", + "In contrast to the data type `Integer`, the data type `Float` is used to represent [floating point\n", + "numbers](https://en.wikipedia.org/wiki/Floating-point_arithmetic). Decimal places are separated by a dot (`.`). As shown\n", + "in the following cell, the data type `Float` also supports the exponential notation. The notation 6.62e-34 represents the\n", + "number $ 6.62 * 10^{-34} $." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(type(0.1))\n", + "print(type(0.0))\n", + "\n", + "h = 6.63e-34 # https://en.wikipedia.org/wiki/Planck_constant\n", + "print(h)\n", + "print(type(h))\n", + "\n", + "g = 1e100 # https://en.wikipedia.org/wiki/Googol\n", + "print(g)\n", + "print(type(g))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Operations\n", + "The following table has already been shown in the unit about variables. Once again take a look from the data type point of view. \n", + "\n", + "| Description | Operator | Example | Result |\n", + "| ---------------- | -------- | -------- | ------------------ |\n", + "| Addition | + | 2 + 3 | 5 |\n", + "| Subtraction | - | 2 - 3 | -1 |\n", + "| Multiplication | * | 2 * 3 | 6 |\n", + "| Division | / | 7 / 3 | 2.3333333333333335 |\n", + "| Integer division | // | 7 // 3 | 2 |\n", + "| Modulo | % | 7 % 3 | 1 |\n", + "| Exponentiation | ** | 2 ** 0.5 | 1.4142135623730951 |\n", + "\n", + "As you can see, most of the operations have two integers as input an lead to the data type integer as output. Only the division `/` returns the data type float. As can be seen in the last example, combinations of integer and float are possible as well. In the given case they result in the data type float." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise\n", + "Test different operations for the data types `Integer` and `Float`. Use the function `type()` to determine the data type\n", + "of a variable.\n", + "\n", + "Which data type is created when an `Integer` value is combined with a `Float` value using an operator? Will operations with `Integer` values always result in an `Integer` value?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "integer_value = 5\n", + "print(type(integer_value))\n", + "\n", + "float_value = 6.78\n", + "print(type(float_value))\n", + "\n", + "combinated_value = integer_value + float_value\n", + "print(\"The combined value's type is:\", type(combinated_value))\n", + "\n", + "# More values for experimentations:\n", + "print(-12345678900000000000.0)\n", + "print(3 / 1)\n", + "print(2e306 * 10)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Accuracy of operations on 'float' values\n", + "Execute the calculations in the following two cells.\n", + "\n", + "Are the calculated results correct? What could be the cause of these results?" + ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0.30000000000000004\n" + ] + } + ], + "source": [ + "a = 0.1\n", + "b = 0.2\n", + "\n", + "sum = a + b\n", + "print(sum)" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "2.0000000000000004\n" + ] + } + ], + "source": [ + "root_of_2 = 2**0.5\n", + "\n", + "two = root_of_2**2\n", + "print(two)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Internally Python represents floating point numbers with a precision of 15 to 16 digits in the binary system\n", + "([IEEE_754](https://de.wikipedia.org/wiki/IEEE_754)). This representation allows to work with both very large and very\n", + "small numbers. However, rounding errors occur in certain cases. Some numbers cannot be represented precisely in the\n", + "binary system (similar to the number $1/3$ in the decimal system).\n", + "\n", + "Some more examples of possible surprises when working with floating point numbers can be found in the\n", + "[Python Documentation](https://docs.python.org/3/tutorial/floatingpoint.html)." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# More data types\n", + "## Boolean\n", + "Truth values are represented with the `Boolean` data type. The `Boolean` data type can only take two values: `True` or\n", + "`False`.\n", + "\n", + "There is a set of special logical operators for the `Boolean` data type.\n", + "\n", + "| Operator | Explanation | Example |\n", + "| -------- | ----------- | ----------- |\n", + "| not | Negation | not y |\n", + "| and | Logical AND | x and y |\n", + "| or | Logical OR | a or b or c |" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### Exercise\n", + "In the following cell you will find some examples for the use of `Boolean` values. What happens when you combine a\n", + "`Boolean` value with an `Integer` value? What happens when you combine a `Boolean` value with a `Float` value? What\n", + "operators can you use for this? Of which data type is the result?" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n", + "True\n", + "True and True: True\n", + "a and b: False\n", + "a or b: True\n", + "Complex logical expression: False\n" + ] + } + ], + "source": [ + "print(False and False)\n", + "print(not False)\n", + "\n", + "a = True\n", + "b = False\n", + "\n", + "print(\"True and True: \", True and True)\n", + "print(\"a and b: \", a and b)\n", + "print(\"a or b: \", a or b)\n", + "\n", + "print(\"Complex logical expression: \", a and (b or (True and False)))" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## String\n", + "To process character strings, the `String` data type is used. Strictly speaking `String` is not a primitive data type, but\n", + "a [sequence data type](https://docs.python.org/3/library/stdtypes.html#typesseq). Since strings happen to occur very\n", + "often in simple programs, the data type `String` will be introduced nevertheless.\n", + "\n", + "In Python, `Strings` can be created with either single or double quotes. There are subtle differences between the two\n", + "variations, which will not be discussed further at this point. We will prefer to use double quotes (`\"`) when working\n", + "with `Strings`.\n", + "\n", + "In the following cell you can see, that it is possible to use the `+` operator not only on integers (and floats) but as well on strings. Moreover, it is possible to multiply a string with an interger. What happens, if you multiply a string with a float?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "print(type(\"Hello World\"))\n", + "\n", + "a = \"Hello\"\n", + "b = \"World\"\n", + "\n", + "print(a, b)\n", + "print(a + b)\n", + "\n", + "print(3 * a)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "### String methods\n", + "There are a number of [methods](https://docs.python.org/3/library/string.html). in Python to process `Strings`.\n", + "\n", + "A small selection of these methods is shown below:\n", + "* `.lower()`: changes all upper case letters to lower case\n", + "* `.upper()`: changes all lowercase letters to uppercase\n", + "* `.replace()`: is used to replace a given sequence within a `String` with another one" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "#### Exercise\n", + "Test different operations for `Strings`.\n", + "What happens when you try to add a `string` and an `integer`?\n", + "Also use the above methods to manipulate `Strings`." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "a = \"Ramones\"\n", + "print(a.upper())\n", + "\n", + "print(\"hitchhiker\".replace(\"hi\", \"ma\"))" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The sum is: 1020\n" + ] + } + ], + "source": [ + "#### Exercise\n", + "# Get two numbers from the user using input()\n", + "num1 = input(\"Enter the first number: \")\n", + "num2 = input(\"Enter the second number: \")\n", + "\n", + "# Add the two numbers\n", + "result = num1 + num2\n", + "\n", + "# Print the result\n", + "print(\"The sum is:\", result)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "ename": "SyntaxError", + "evalue": "invalid syntax (1573619940.py, line 5)", + "output_type": "error", + "traceback": [ + "\u001b[1;36m Cell \u001b[1;32mIn[6], line 5\u001b[1;36m\u001b[0m\n\u001b[1;33m b =\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid syntax\n" + ] + } + ], + "source": [ + "a = input(\"Please insert a number A: \")\n", + "\n", + "# Please add your code in the following lines\n", + "\n", + "b = " + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# Conversion\n", + "Operations on `Strings` sometimes lead to unexpected results. The attempt to add a `String` and an `Integer` leads to an\n", + "error message. The addition of two `Strings` causes both strings to be concatenated.\n", + "\n", + "This is a common problem when working with user input. The data type of the input is always `String`. This may have to be\n", + "converted to a different data type before it can be used. For the conversion between the different data types, Python\n", + "provides a number of [built-in functions](https://docs.python.org/3/library/functions.html):\n", + "\n", + "| Function | Explanation | Example |\n", + "| -------- | -------------------------------------------------------- | -------------- |\n", + "| int() | Converts the passed parameter to the data type `Integer` | int(\"10\") |\n", + "| float() | Converts the given parameter to the data type `float` | float(\"3.14\") |\n", + "| bool() | Converts the given parameter to the data type `Boolean` | bool(\"Hello \") |\n", + "| str() | Converts the given parameter to the data type `String` | str(True) |" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Exercise\n", + "Perform some conversions between the different data types. Analyze which data type and which value the result of the\n", + "conversion has. What happens when you concatenate different conversions?" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "s = \"Hello\"\n", + "i = 2019\n", + "print(s + str(i))\n", + "\n", + "print(bool(0))\n", + "\n", + "print(int(bool(3)))\n", + "\n", + "bool(\" \")" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Converting and the function `input()`\n", + "As already mentioned, the result of the `input()` function is always a `String`. If you need another data type, you must\n", + "convert the input data at first. The necessary procedure is shown in the following cells." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "43\n", + "\n" + ] + } + ], + "source": [ + "age = input(\"Please insert your age: \")\n", + "age = int(age)\n", + "print(age)\n", + "print(type(age))" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "# Alternatively it is also possible to nest these functions\n", + "age = int(input(\"Please insert your Age: \"))\n", + "print(type(age))" + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The surface area of the cuboid is: 8860.0\n", + "The volume of the cuboid is: 49000.0\n" + ] + } + ], + "source": [ + "# Get the dimensions of the cuboid from the user\n", + "length = float(input(\"Enter the length of the cuboid: \"))\n", + "width = float(input(\"Enter the width of the cuboid: \"))\n", + "height = float(input(\"Enter the height of the cuboid: \"))\n", + "\n", + "# Calculate the surface area of the cuboid\n", + "surface_area = 2 * (length * width + width * height + height * length)\n", + "\n", + "# Calculate the volume of the cuboid\n", + "volume = length * width * height\n", + "\n", + "# Output the results\n", + "print(\"The surface area of the cuboid is:\", surface_area)\n", + "print(\"The volume of the cuboid is:\", volume)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n" + ] + } + ], + "source": [ + "### Exercise 2\n", + "\n", + "amount_us_presidencies = 46 # Example value, representing the number of US presidencies\n", + "type_of_variable = type(amount_us_presidencies) # Get the type of the variable\n", + "print(type_of_variable) # Print the type\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "file_extension": ".py", + "interpreter": { + "hash": "ae5a99a2531053e9be9d669b7bfc08eaacd0186491e01eb4522a2d385742a1d5" + }, + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.13.0" + }, + "mimetype": "text/x-python", + "name": "python", + "npconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": 3 + }, + "nbformat": 4, + "nbformat_minor": 2 +} diff --git a/week_1/w1u5.ipynb b/week_1/w1u5.ipynb index 812fed3..e7ee152 100644 --- a/week_1/w1u5.ipynb +++ b/week_1/w1u5.ipynb @@ -192,9 +192,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5 is smaller oder equals 100!\n", + "Done\n" + ] + } + ], "source": [ "number = int(input(\"Please insert a number: \"))\n", "if number > 100:\n", @@ -205,20 +214,46 @@ ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], + "source": [ + "#it will not run if it is indented. it throws a syntax error." + ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Welcome to Gryffindor, Mr. Potter!\n" + ] + } + ], "source": [ "### Exercise\n", - "Write a conditional statement that asks for the user's name. Use the `input()` function. If his name is Harry or Harry Potter, then output \"Welcome to Gryffindor, Mr. Potter!\". Otherwise output \"Sorry, Hogwarts is full.\". " + "# Ask for the user's name\n", + "user_name = input(\"What is your name? \")\n", + "\n", + "# Conditional statement to check the name\n", + "if user_name == \"Harry\" or user_name == \"Harry Potter\":\n", + " print(\"Welcome to Gryffindor, Mr. Potter!\")\n", + "else:\n", + " print(\"Sorry, Hogwarts is full.\")\n" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ - "name = " + "name = input" ] } ], @@ -242,7 +277,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -252,4 +287,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_1/w1u6.ipynb b/week_1/w1u6.ipynb index 6c6543d..82d2429 100644 --- a/week_1/w1u6.ipynb +++ b/week_1/w1u6.ipynb @@ -117,10 +117,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Money is issued. Your new account balance is: $275.00\n" + ] + } + ], + "source": [ + "# Constants\n", + "CORRECT_PIN = \"8898\" # Example PIN\n", + "account_balance = 775 # Example account balance\n", + "\n", + "# Step 1: Ask for the PIN\n", + "entered_pin = input(\"Please enter your PIN: \")\n", + "\n", + "# Step 2: Compare the input with the constant\n", + "if entered_pin == CORRECT_PIN:\n", + " # Step 3: Ask how much money to withdraw\n", + " withdrawal_amount = float(input(\"How much money would you like to withdraw? \"))\n", + " \n", + " # Step 4: Compare the amount with the account balance\n", + " if withdrawal_amount <= account_balance:\n", + " # Step 5: Display success message and new account balance\n", + " account_balance -= withdrawal_amount\n", + " print(f\"Money is issued. Your new account balance is: ${account_balance:.2f}\")\n", + " else:\n", + " # Step 6: Display error message for insufficient funds\n", + " print(\"Error: Insufficient funds in your account.\")\n", + "else:\n", + " # Step 7: Display error message for incorrect PIN\n", + " print(\"Error: Incorrect PIN.\")\n" + ] } ], "metadata": { @@ -143,7 +175,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -153,4 +185,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_1/w1u7.ipynb b/week_1/w1u7.ipynb index b2390a5..2fd4221 100644 --- a/week_1/w1u7.ipynb +++ b/week_1/w1u7.ipynb @@ -141,16 +141,57 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "It's warm\n", + "Warm & raining: summer in Aachen\n", + "Warm, raining, no wind at all\n" + ] + } + ], "source": [ - "# Start your try here..." + "temperature = int(input(\"Please insert the current temperature: \"))\n", + "rain = True\n", + "wind = False\n", + "\n", + "if temperature > 20:\n", + " print(\"It's warm\")\n", + "\n", + " # Check for rain\n", + " if rain:\n", + " print(\"Warm & raining: summer in Aachen\")\n", + "\n", + " # Check for wind\n", + " if wind:\n", + " print(\"It's warm, it rains and it's windy!\")\n", + " else:\n", + " if rain:\n", + " print(\"Warm, raining, no wind at all\")\n", + " else:\n", + " print(\"Warm and dry, beautiful!\")\n", + "\n", + " # Check for wind when it's dry\n", + " if not rain:\n", + " if wind:\n", + " print(\"Warm, dry and windy: Good weather for sailing\")\n", + " else:\n", + " print(\"Warm, dry, windless: Just lie in the sun\")\n", + "else:\n", + " print(\"If it's cold, I don't care about rain and wind\")\n", + "\n", + " " ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Exercise 2\n", "As is well known, a calendar year has 365 or 366 days. According to the Gregorian calendar, a year lasts exactly\n", @@ -170,19 +211,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The year 1979 is not a leap year.\n" + ] + } + ], + "source": [ + "# Function to check if a year is a leap year\n", + "def is_leap_year(year):\n", + " if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):\n", + " return True\n", + " else:\n", + " return False\n", + "\n", + "# Input from the user\n", + "year = int(input(\"Enter a year: \"))\n", + "\n", + "# Check and output whether it's a leap year\n", + "if is_leap_year(year):\n", + " print(f\"The year {year} is a leap year.\")\n", + "else:\n", + " print(f\"The year {year} is not a leap year.\")\n" + ] } ], "metadata": { "file_extension": ".py", - "interpreter": { - "hash": "ac59ebe37160ed0dfa835113d9b8498d9f09ceb179beaac4002f036b9467c963" - }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -196,7 +258,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -206,4 +268,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_2/w2final.ipynb b/week_2/w2final.ipynb index 1b0d5f4..7ea79f2 100644 --- a/week_2/w2final.ipynb +++ b/week_2/w2final.ipynb @@ -47,9 +47,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Production quantity month 0 - 0\n", + "Production quantity month 1 - 50\n", + "Production quantity month 2 - 200\n", + "Production quantity month 3 - 400\n", + "Production quantity month 4 - 100\n" + ] + } + ], "source": [ "stock = int(input(\"Please enter an initial stock level: \"))\n", "num_months = int(input(\"Please enter the number of month to plan: \"))\n", @@ -75,10 +87,44 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Month 1: Production quantity: 0, Sales quantity: 400, Remaining stock level: 100\n", + "Month 2: Production quantity: 50, Sales quantity: 300, Remaining stock level: -150\n", + "Month 3: Production quantity: 200, Sales quantity: 200, Remaining stock level: -150\n", + "Month 4: Production quantity: 400, Sales quantity: 100, Remaining stock level: 150\n", + "Month 5: Production quantity: 100, Sales quantity: 50, Remaining stock level: 200\n" + ] + } + ], + "source": [ + "# Input the initial stock level for the product\n", + "initial_stock = int(input(\"Enter the initial stock level: \"))\n", + "\n", + "# Known production quantities for each month\n", + "production_quantities = [0, 50, 200, 400, 100] # Production quantities for months 1 to 5\n", + "num_months = len(production_quantities)\n", + "\n", + "# Initialize variables\n", + "stock_level = initial_stock # This holds the stock level for the current month\n", + "\n", + "# Loop through each month to calculate the remaining stock after sales\n", + "for month in range(1, num_months + 1):\n", + " # Input the planned sales quantity for the current month\n", + " sales_quantity = int(input(f\"Enter the planned sales quantity for month {month}: \"))\n", + "\n", + " # Calculate the stock after production and sales\n", + " stock_level += production_quantities[month - 1] # Add production for this month\n", + " stock_level -= sales_quantity # Subtract the sales quantity\n", + "\n", + " # Output the production, sales, and remaining stock level for this month\n", + " print(f\"Month {month}: Production quantity: {production_quantities[month - 1]}, Sales quantity: {sales_quantity}, Remaining stock level: {stock_level}\")\n" + ] } ], "metadata": { @@ -97,9 +143,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/week_2/w2u1.ipynb b/week_2/w2u1.ipynb index 23a1460..4e5c5ae 100644 --- a/week_2/w2u1.ipynb +++ b/week_2/w2u1.ipynb @@ -37,9 +37,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[0, 1, 1, 2, 3, 5, 8, 13, 21]\n" + ] + } + ], "source": [ "my_number_list = [0, 1, 1, 2, 3, 5, 8, 13, 21]\n", "print(my_number_list)" @@ -56,9 +64,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Hello', 'open', 'SAP']\n" + ] + } + ], "source": [ "my_string_list = [\"Hello\", \"open\", \"SAP\"]\n", "my_float_list = [3.14, -6.63e-34]\n", @@ -77,9 +93,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 3, 5, True, -23, 'a', 3.234, 'abc']\n" + ] + } + ], "source": [ "my_mixed_list = [1, 3, 5, True, -23, \"a\", 3.234, \"abc\"]\n", "print(my_mixed_list)" @@ -108,9 +132,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6]\n", + "[1, 2, 3, 1, 2, 3, 1, 2, 3]\n" + ] + } + ], "source": [ "first_list = [1, 2, 3]\n", "second_list = [4, 5, 6]\n", @@ -132,9 +165,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The list contains the number 7\n" + ] + } + ], "source": [ "prime_numbers = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]\n", "my_number = int(input(\"Please enter a number: \"))\n", @@ -144,6 +185,47 @@ "else:\n", " print(\"The list does not contain the number\", my_number)" ] + }, + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\n", + "Your sorted shopping list:\n", + "bread\n", + "chips\n", + "eggs\n", + "milk\n", + "water\n" + ] + } + ], + "source": [ + "# Initialize an empty list to store the shopping list items\n", + "shopping_list = []\n", + "\n", + "# Input loop for user to enter products\n", + "while True:\n", + " product = input(\"Enter a product for your shopping list (or type 'done' to finish): \")\n", + " \n", + " if product.lower() == 'done': # Check if the user wants to stop entering products\n", + " break # Exit the loop\n", + " else:\n", + " shopping_list.append(product) # Add the product to the shopping list\n", + "\n", + "# Sort the shopping list alphabetically\n", + "shopping_list.sort()\n", + "\n", + "# Output the sorted shopping list\n", + "print(\"\\nYour sorted shopping list:\")\n", + "for item in shopping_list:\n", + " print(item)\n" + ] } ], "metadata": { @@ -165,9 +247,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_2/w2u2.ipynb b/week_2/w2u2.ipynb index 9422ee8..6562642 100644 --- a/week_2/w2u2.ipynb +++ b/week_2/w2u2.ipynb @@ -19,9 +19,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "pear\n" + ] + } + ], "source": [ "fruit_list = [\"apple\", \"banana\", \"coconut\", \"pear\", \"prune\"]\n", "fruit = fruit_list[3]\n", @@ -55,9 +63,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "prune\n", + "prune\n", + "apple\n" + ] + } + ], "source": [ "fruit_list = [\"apple\", \"banana\", \"coconut\", \"pear\", \"prune\"]\n", "print(fruit_list[4])\n", @@ -76,9 +94,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 3, 4, 7, 11, 13, 17]\n", + "[2, 3, 5, 7, 11, 13, 17]\n" + ] + } + ], "source": [ "some_primes_list = [2, 3, 4, 7, 11, 13, 17]\n", "print(some_primes_list)\n", @@ -99,9 +126,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "IndexError", + "evalue": "list index out of range", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mIndexError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[4], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m fruit_list \u001b[38;5;241m=\u001b[39m [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mapple\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mbanana\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcoconut\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdamson\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124melderberry\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m----> 2\u001b[0m \u001b[43mfruit_list\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m10\u001b[39;49m\u001b[43m]\u001b[49m\n", + "\u001b[1;31mIndexError\u001b[0m: list index out of range" + ] + } + ], "source": [ "fruit_list = [\"apple\", \"banana\", \"coconut\", \"damson\", \"elderberry\"]\n", "fruit_list[10]" @@ -135,9 +174,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Never Mind the Bollocks', 'Flogging a Dead Horse', 'Anarchy in the UK']\n", + "Road to Ruin\n" + ] + } + ], "source": [ "records = [\n", " [\"Ramones\", \"Leave Home\", \"Rocket to Russia\", \"Road to Ruin\"],\n", @@ -165,9 +213,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "y\n", + "o\n", + "Happy Python 🐍 Programming!\n" + ] + } + ], "source": [ "course_name = \"Python Introduction\"\n", "print(course_name[1])\n", @@ -176,6 +234,15 @@ "if \"Python\" in course_name:\n", " print(\"Happy Python 🐍 Programming!\")" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#reviewed and ran code to see examples of what works and what does not " + ] } ], "metadata": { @@ -197,9 +264,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_2/w2u3.ipynb b/week_2/w2u3.ipynb index 12cd7e1..6e6798f 100644 --- a/week_2/w2u3.ipynb +++ b/week_2/w2u3.ipynb @@ -24,9 +24,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The fruit list contains 5 items.\n", + "Python Introduction consists of 19 characters.\n" + ] + } + ], "source": [ "fruit_list = [\"apple\", \"banana\", \"coconut\", \"pear\", \"prune\"]\n", "print(\"The fruit list contains\", len(fruit_list), \"items.\")\n", @@ -46,9 +55,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The lowest price was: 120.8 €.\n", + "The highest price was: 125.46 €.\n" + ] + } + ], "source": [ "sap_stock_price = [120.80, 121.68, 123.90, 125.46, 124.62, 124.88, 124.04, 123.54]\n", "print(\"The lowest price was:\", min(sap_stock_price), \"€.\")\n", @@ -66,9 +84,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[7, 3, 6, 7, 12, 45, -21]\n", + "[-21, 3, 6, 7, 7, 12, 45]\n", + "[' ', 'I', 'P', 'c', 'd', 'h', 'i', 'n', 'n', 'n', 'o', 'o', 'o', 'r', 't', 't', 't', 'u', 'y']\n" + ] + } + ], "source": [ "random_numbers = [7, 3, 6, 7, 12, 45, -21]\n", "sorted_numbers = sorted(random_numbers)\n", @@ -88,9 +116,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "'<' not supported between instances of 'str' and 'int'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[4], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m unsortable_list \u001b[38;5;241m=\u001b[39m [\u001b[38;5;28;01mTrue\u001b[39;00m, \u001b[38;5;241m56\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mabc\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43msorted\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43munsortable_list\u001b[49m\u001b[43m)\u001b[49m)\n", + "\u001b[1;31mTypeError\u001b[0m: '<' not supported between instances of 'str' and 'int'" + ] + } + ], "source": [ "unsortable_list = [True, 56, \"abc\"]\n", "print(sorted(unsortable_list))" @@ -108,9 +148,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[-21, 3, 6, 7, 7, 12, 45]\n" + ] + } + ], "source": [ "random_numbers = [7, 3, 6, 7, 12, 45, -21]\n", "random_numbers.sort()\n", @@ -137,9 +185,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 10]\n" + ] + } + ], "source": [ "numbers = [1, 2, 3, 4]\n", "numbers.append(10)\n", @@ -156,9 +212,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3]\n", + "4\n" + ] + } + ], "source": [ "numbers = [1, 2, 3, 4]\n", "last_item = numbers.pop()\n", @@ -178,9 +243,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 10, 3, 4]\n" + ] + } + ], "source": [ "numbers = [1, 2, 3, 4]\n", "numbers.insert(2, 10)\n", @@ -196,9 +269,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 4, 3, 2, 1]\n" + ] + } + ], "source": [ "numbers = [1, 2, 3, 4, 3, 2, 1]\n", "numbers.remove(3)\n", @@ -235,9 +316,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_2/w2u4.ipynb b/week_2/w2u4.ipynb index a3770da..935adec 100644 --- a/week_2/w2u4.ipynb +++ b/week_2/w2u4.ipynb @@ -40,9 +40,40 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "H\n", + "e\n", + "l\n", + "l\n", + "o\n", + " \n", + "P\n", + "y\n", + "t\n", + "h\n", + "o\n", + "n\n", + " \n", + "p\n", + "r\n", + "o\n", + "g\n", + "r\n", + "a\n", + "m\n", + "m\n", + "i\n", + "n\n", + "g\n" + ] + } + ], "source": [ "for char in \"Hello Python programming\":\n", " print(char)" @@ -57,9 +88,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "3\n", + "4\n", + "234\n", + "-12\n", + "abc\n", + "True\n" + ] + } + ], "source": [ "list1 = [3, 4, 234, -12, \"abc\", True]\n", "for element in list1:\n", @@ -86,9 +130,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The minmum of the list is: 68\n" + ] + } + ], "source": [ "# list1 contains some random values between 0 and 1000\n", "list1 = [\n", @@ -149,10 +201,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "h my name s amanda\n" + ] + } + ], + "source": [ + "# Prompt the user for a sentence and a letter to remove\n", + "sentence = input(\"What sentence should be output? \")\n", + "letter_to_remove = input(\"Which letter should be removed? \")\n", + "\n", + "# Initialize an empty string to store the result\n", + "result = \"\"\n", + "\n", + "# Iterate over each letter in the sentence\n", + "for letter in sentence:\n", + " # If the letter is not the one to be removed, add it to the result\n", + " if letter != letter_to_remove:\n", + " result += letter\n", + " \n", + " # If the result string exceeds 20 characters, break the loop\n", + " if len(result) > 20:\n", + " break\n", + "\n", + "# Output the result, constrained to a maximum of 20 characters\n", + "print(result[:20]) # Print only the first 20 characters of the result\n" + ] } ], "metadata": { @@ -174,9 +254,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_2/w2u5.ipynb b/week_2/w2u5.ipynb index 1e1b5f7..0036c16 100644 --- a/week_2/w2u5.ipynb +++ b/week_2/w2u5.ipynb @@ -41,9 +41,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "1\n", + "2\n", + "3\n", + "4\n", + "5\n", + "6\n", + "7\n", + "8\n", + "9\n" + ] + } + ], "source": [ "for number in range(10):\n", " print(number)" @@ -58,9 +75,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "11\n", + "12\n", + "13\n", + "14\n", + "15\n", + "16\n", + "17\n", + "18\n", + "19\n" + ] + } + ], "source": [ "for number in range(10, 20):\n", " print(number)" @@ -76,9 +110,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "8\n", + "6\n", + "4\n", + "2\n" + ] + } + ], "source": [ "for number in range(10, 0, -2):\n", " print(number)" @@ -96,10 +142,76 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "3\n", + "5\n", + "7\n", + "9\n", + "11\n", + "13\n", + "15\n", + "17\n", + "19\n", + "21\n", + "23\n", + "25\n", + "27\n", + "29\n", + "31\n", + "33\n", + "35\n", + "37\n", + "39\n", + "41\n", + "43\n", + "45\n", + "47\n", + "49\n", + "51\n", + "53\n", + "55\n", + "57\n", + "59\n", + "61\n", + "63\n", + "65\n", + "67\n", + "69\n", + "71\n", + "73\n", + "75\n", + "77\n", + "79\n", + "81\n", + "83\n", + "85\n", + "87\n", + "89\n", + "91\n", + "93\n", + "95\n", + "97\n", + "99\n" + ] + } + ], + "source": [ + "# Prompt the user for the starting number, ending number, and increment\n", + "start = int(input(\"Enter the starting number: \"))\n", + "end = int(input(\"Enter the ending number: \"))\n", + "increment = int(input(\"Enter the increment: \"))\n", + "\n", + "# Output the numbers in the specified range using the given increment\n", + "for number in range(start, end, increment):\n", + " print(number)\n" + ] }, { "cell_type": "markdown", @@ -124,19 +236,173 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "Fizz\n", + "4\n", + "Buzz\n", + "Fizz\n", + "7\n", + "8\n", + "Fizz\n", + "Buzz\n", + "11\n", + "Fizz\n", + "13\n", + "14\n", + "FizzBuzz\n", + "16\n", + "17\n", + "Fizz\n", + "19\n", + "Buzz\n", + "Fizz\n", + "22\n", + "23\n", + "Fizz\n", + "Buzz\n", + "26\n", + "Fizz\n", + "28\n", + "29\n", + "FizzBuzz\n", + "31\n", + "32\n", + "Fizz\n", + "34\n", + "Buzz\n", + "Fizz\n", + "37\n", + "38\n", + "Fizz\n", + "Buzz\n", + "41\n", + "Fizz\n", + "43\n", + "44\n", + "FizzBuzz\n", + "46\n", + "47\n", + "Fizz\n", + "49\n", + "Buzz\n", + "Fizz\n", + "52\n", + "53\n", + "Fizz\n", + "Buzz\n", + "56\n", + "Fizz\n", + "58\n", + "59\n", + "FizzBuzz\n", + "61\n", + "62\n", + "Fizz\n", + "64\n", + "Buzz\n", + "Fizz\n", + "67\n", + "68\n", + "Fizz\n", + "Buzz\n", + "71\n", + "Fizz\n", + "73\n", + "74\n", + "FizzBuzz\n", + "76\n", + "77\n", + "Fizz\n", + "79\n", + "Buzz\n", + "Fizz\n", + "82\n", + "83\n", + "Fizz\n", + "Buzz\n", + "86\n", + "Fizz\n", + "88\n", + "89\n", + "FizzBuzz\n", + "91\n", + "92\n", + "Fizz\n", + "94\n", + "Buzz\n", + "Fizz\n", + "97\n", + "98\n", + "Fizz\n", + "Buzz\n" + ] + } + ], + "source": [ + "# Loop through numbers from 1 to 100\n", + "for number in range(1, 101):\n", + " # Check if the number is divisible by both 3 and 5\n", + " if number % 3 == 0 and number % 5 == 0:\n", + " print(\"FizzBuzz\")\n", + " # Check if the number is divisible by 3\n", + " elif number % 3 == 0:\n", + " print(\"Fizz\")\n", + " # Check if the number is divisible by 5\n", + " elif number % 5 == 0:\n", + " print(\"Buzz\")\n", + " # If the number is not divisible by 3 or 5, print the number itself\n", + " else:\n", + " print(number)\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "udymts nx utbjmtzxj\n" + ] + } + ], + "source": [ + "def caesar_cipher(plain_text):\n", + " shift = 5\n", + " encrypted_text = \"\"\n", + "\n", + " for char in plain_text:\n", + " if char.isalpha(): # Check if character is a letter\n", + " shift_base = ord('a') if char.islower() else ord('A')\n", + " encrypted_char = chr((ord(char) - shift_base + shift) % 26 + shift_base)\n", + " encrypted_text += encrypted_char\n", + " else:\n", + " encrypted_text += char # Keep non-alphabet characters unchanged\n", + "\n", + " return encrypted_text\n", + "\n", + "if __name__ == \"__main__\":\n", + " plain_text = input(\"Enter text to encrypt: \")\n", + " # Call the function to get the encrypted text\n", + " encrypted = caesar_cipher(plain_text) # Ensure you assign the output here\n", + " print(encrypted) # Print only the encrypted text\n" + ] } ], "metadata": { "file_extension": ".py", - "interpreter": { - "hash": "ac59ebe37160ed0dfa835113d9b8498d9f09ceb179beaac4002f036b9467c963" - }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -150,7 +416,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -160,4 +426,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_2/w2u6.ipynb b/week_2/w2u6.ipynb index 6b1a6ad..ae4c591 100644 --- a/week_2/w2u6.ipynb +++ b/week_2/w2u6.ipynb @@ -51,9 +51,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Number 4 in list? True\n", + "Number 10 in list? False\n", + "String contains s! True\n", + "The range contains the number 27: False\n", + "Those strings were concatenated\n" + ] + }, + { + "ename": "TypeError", + "evalue": "unsupported operand type(s) for *: 'int' and 'range'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 13\u001b[0m\n\u001b[0;32m 9\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThe range contains the number 27:\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;241m27\u001b[39m \u001b[38;5;129;01min\u001b[39;00m range_100)\n\u001b[0;32m 11\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mThose str\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;241m+\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mings were concatenated\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m---> 13\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;241;43m5\u001b[39;49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43m \u001b[49m\u001b[43mrange_100\u001b[49m)\n\u001b[0;32m 15\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mmin\u001b[39m(list_l))\n", + "\u001b[1;31mTypeError\u001b[0m: unsupported operand type(s) for *: 'int' and 'range'" + ] + } + ], "source": [ "list_l = [1, 2, 3, 4, 5, 6]\n", "string_s = \"This is a string, right?\"\n", @@ -75,11 +98,8 @@ ], "metadata": { "file_extension": ".py", - "interpreter": { - "hash": "ac59ebe37160ed0dfa835113d9b8498d9f09ceb179beaac4002f036b9467c963" - }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -93,7 +113,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -103,4 +123,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_2/w2u7.ipynb b/week_2/w2u7.ipynb index d626351..8000fbb 100644 --- a/week_2/w2u7.ipynb +++ b/week_2/w2u7.ipynb @@ -30,9 +30,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[4, 6]\n", + "[0, 2, 4]\n", + "[6, 8, 10]\n", + "[0, 2, 4, 6, 8, 10]\n", + "lo Wo\n" + ] + } + ], "source": [ "even_numbers = [0, 2, 4, 6, 8, 10]\n", "print(even_numbers[2:4])\n", @@ -64,9 +76,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "8\n", + "[7, 8]\n", + "[1, 2, 3, 4, 5]\n" + ] + } + ], "source": [ "numbers = [1, 2, 3, 4, 5, 6, 7, 8]\n", "print(numbers[-1])\n", @@ -88,9 +110,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]\n", + "[2, 4, 6, 8, 10]\n" + ] + } + ], "source": [ "numbers = list(range(1, 11))\n", "print(numbers)\n", @@ -127,14 +158,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Original list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]\n", + "Reversed list: [5, 4]\n", + "Only the last 3 items: [15, 14, 13]\n" + ] + } + ], "source": [ "numbers = list(range(1, 16))\n", "print(\"Original list:\", numbers)\n", "\n", - "print(\"Reversed list:\", numbers[::-1])\n", + "print(\"Reversed list:\", numbers[4:2:-1])\n", "\n", "print(\"Only the last 3 items:\", numbers[:-4:-1])" ] @@ -151,10 +192,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Elements from index 0 to 4: [1, 2, 3, 4, 5]\n", + "Elements from index 4 to 8: [5, 6, 7, 8, 9]\n", + "Elements from index 8 to 10: [9, 10, 11]\n" + ] + } + ], + "source": [ + "# Create a list with elements from 1 to 20\n", + "numbers = list(range(1, 21))\n", + "\n", + "# Output elements at index 0-4 (slices from index 0 to 4, excluding 5)\n", + "print(\"Elements from index 0 to 4:\", numbers[0:5])\n", + "\n", + "# Output elements at index 4-8 (slices from index 4 to 8, excluding 9)\n", + "print(\"Elements from index 4 to 8:\", numbers[4:9])\n", + "\n", + "# Output elements at index 8-10 (slices from index 8 to 10, excluding 11)\n", + "print(\"Elements from index 8 to 10:\", numbers[8:11])\n" + ] } ], "metadata": { @@ -177,7 +240,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -187,4 +250,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_2/w2u8.ipynb b/week_2/w2u8.ipynb index 03cb279..98407bb 100644 --- a/week_2/w2u8.ipynb +++ b/week_2/w2u8.ipynb @@ -29,9 +29,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The list of squares is: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]\n" + ] + } + ], "source": [ "numbers = list(range(1, 21))\n", "\n", @@ -57,9 +65,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The list of squares is: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]\n" + ] + } + ], "source": [ "numbers = list(range(1, 21))\n", "squares = [x ** 2 for x in numbers]\n", @@ -82,9 +98,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The list of squares is: [1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256, 289, 324, 361, 400]\n" + ] + } + ], "source": [ "squares = [x ** 2 for x in range(1, 21)]\n", "print(\"The list of squares is:\", squares)" @@ -103,9 +127,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The possible combinations of letters and numbers are: ['A1', 'A2', 'A3', 'B1', 'B2', 'B3', 'C1', 'C2', 'C3']\n" + ] + } + ], "source": [ "letters = [\"A\", \"B\", \"C\"]\n", "numbers = [1, 2, 3]\n", @@ -128,9 +160,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The songs that were played at least 30 times are: [['Ace of Spades', 99], ['Anarchy in the UK', 51], ['Blue Train', 42], ['Paranoid', 33]]\n" + ] + } + ], "source": [ "songs = [\n", " [\"Ace of Spades\", 99],\n", @@ -160,9 +200,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The songs that were played at least 30 times are: [['Ace of Spades', 99], ['Anarchy in the UK', 51], ['Blue Train', 42], ['Paranoid', 33]]\n" + ] + } + ], "source": [ "songs = [\n", " [\"Ace of Spades\", 99],\n", @@ -199,9 +247,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_3/w3bonus.ipynb b/week_3/w3bonus.ipynb index 159cb1a..ef26ae8 100644 --- a/week_3/w3bonus.ipynb +++ b/week_3/w3bonus.ipynb @@ -87,9 +87,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dpdqgd oryhv sbwkrq\n" + ] + } + ], "source": [ "abc = \"abcdefghijklmnopqrstuvwxyz\"\n", "\n", @@ -108,6 +116,26 @@ " \n", "print(secret_text)" ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "test\n" + ] + } + ], + "source": [ + "#ran example just to see \n", + "s = \"TEST\"\n", + "s = s.lower()\n", + "print(s)" + ] } ], "metadata": { @@ -126,9 +154,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/week_3/w3solution.ipynb b/week_3/w3solution.ipynb index 8f0f5ee..1eec8d5 100644 --- a/week_3/w3solution.ipynb +++ b/week_3/w3solution.ipynb @@ -59,9 +59,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "frfsif qtajx udymts\n" + ] + } + ], "source": [ "substitution = {\n", " \"a\": \"f\",\n", @@ -103,6 +111,25 @@ " \n", "print(secret_text)" ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "test\n" + ] + } + ], + "source": [ + "s = \"TEST\"\n", + "s = s.lower()\n", + "print(s)\n" + ] } ], "metadata": { @@ -121,9 +148,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/week_3/w3u1.ipynb b/week_3/w3u1.ipynb index fb24682..4102e89 100644 --- a/week_3/w3u1.ipynb +++ b/week_3/w3u1.ipynb @@ -14,9 +14,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(52066, 'Aachen', 'Eupener Str. 70', '0241-6009-12345')\n", + "('Peter', 'Meier', 123456, 'SAP basics', 'pm12345s@university.edu', (52066, 'Aachen', 'Eupener Str. 70', '0241-6009-12345'))\n", + "(12312, 'absbsb', [1, 2, 3, 4], ('a', 'b', 'c'), 'end')\n" + ] + } + ], "source": [ "address = (52066, \"Aachen\", \"Eupener Str. 70\", \"0241-6009-12345\")\n", "print(address)\n", @@ -39,9 +49,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a\n" + ] + }, + { + "ename": "TypeError", + "evalue": "'tuple' object does not support item assignment", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m tup \u001b[38;5;241m=\u001b[39m (\u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124ma\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(tup[\u001b[38;5;241m2\u001b[39m])\n\u001b[1;32m----> 3\u001b[0m \u001b[43mtup\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", + "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" + ] + } + ], "source": [ "tup = (1, 2, \"a\")\n", "print(tup[2])\n", @@ -50,9 +79,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1, 2, 3)\n", + "('a', 'b', 'c', 'd')\n" + ] + } + ], "source": [ "tup = (1, 2, 3)\n", "print(tup)\n", @@ -90,9 +128,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('', 'Amanda ', 'Amanda ', '6066878444')\n" + ] + } + ], "source": [ "name = input(\"Please enter name: \")\n", "first_name = input(\"Please enter first name: \")\n", @@ -117,9 +163,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "52066\n", + "Parker\n", + "(52066, 'Aachen', 'Eupener Str. 70', '0241-6009-12345')\n", + "Eupener Str. 70\n", + "(52066, 'Aachen', 'Eupener Str. 70', '0241-6009-12345')\n", + "Aachen\n", + "Eupener Str. 70\n" + ] + } + ], "source": [ "address = (52066, \"Aachen\", \"Eupener Str. 70\", \"0241-6009-12345\")\n", "\n", @@ -151,9 +211,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "TypeError", + "evalue": "'tuple' object does not support item assignment", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[3], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m address \u001b[38;5;241m=\u001b[39m (\u001b[38;5;241m52066\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAachen\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEupener Str. 70\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m0241-6009-12345\u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m----> 2\u001b[0m \u001b[43maddress\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m]\u001b[49m \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mGoethestraße 1\u001b[39m\u001b[38;5;124m\"\u001b[39m\n", + "\u001b[1;31mTypeError\u001b[0m: 'tuple' object does not support item assignment" + ] + } + ], "source": [ "address = (52066, \"Aachen\", \"Eupener Str. 70\", \"0241-6009-12345\")\n", "address[2] = \"Goethestraße 1\"" @@ -178,9 +250,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('trois', 'four')\n", + "6\n", + "1\n", + "4\n" + ] + } + ], "source": [ "numbers = (1, 2, \"trois\", \"four\", \"V\", 6)\n", "print(numbers[2:4])\n", @@ -200,9 +283,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "52066\n", + "Aachen\n", + "Eupener Str. 70\n", + "0241-6009-12345\n" + ] + } + ], "source": [ "address = (52066, \"Aachen\", \"Eupener Str. 70\", \"0241-6009-12345\")\n", "\n", @@ -221,9 +315,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(1, 2, 'a', 2.3)\n", + "[1, 2, 'a', 2.3]\n" + ] + } + ], "source": [ "l = [1, 2, \"a\", 2.3]\n", "t = tuple(l)\n", @@ -234,11 +337,8 @@ } ], "metadata": { - "interpreter": { - "hash": "ac59ebe37160ed0dfa835113d9b8498d9f09ceb179beaac4002f036b9467c963" - }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -252,9 +352,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_3/w3u2.ipynb b/week_3/w3u2.ipynb index 3e3e1c8..ace6aaf 100644 --- a/week_3/w3u2.ipynb +++ b/week_3/w3u2.ipynb @@ -43,9 +43,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'P. McCartney': 123456, 'J. Lennon': 987654321, 'G. Harrison': 11342555, 'R. Starr': 77788832}\n" + ] + } + ], "source": [ "phone_book = {\n", " \"P. McCartney\": 123456,\n", @@ -66,9 +74,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "11342555\n" + ] + } + ], "source": [ "print(phone_book[\"G. Harrison\"])" ] @@ -82,9 +98,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "2", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[3], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mphone_book\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m2\u001b[39;49m\u001b[43m]\u001b[49m)\n", + "\u001b[1;31mKeyError\u001b[0m: 2" + ] + } + ], "source": [ "print(phone_book[2])" ] @@ -103,9 +131,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 4, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'P. Best'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[4], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43mphone_book\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mP. Best\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m)\n", + "\u001b[1;31mKeyError\u001b[0m: 'P. Best'" + ] + } + ], "source": [ "print(phone_book[\"P. Best\"])" ] @@ -121,9 +161,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'P. McCartney': 123456, 'J. Lennon': 987654321, 'G. Harrison': 11342555, 'R. Starr': 77788832, 'Y. Ono': 5463333, 'B. Epstein': 9998777}\n" + ] + } + ], "source": [ "phone_book[\"Y. Ono\"] = 5463333\n", "phone_book[\"B. Epstein\"] = 9998777\n", @@ -142,9 +190,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'P. McCartney': 654321, 'J. Lennon': 987654321, 'G. Harrison': 11342555, 'R. Starr': 77788832, 'Y. Ono': 5463333, 'B. Epstein': 9998777}\n" + ] + } + ], "source": [ "phone_book[\"P. McCartney\"] = 654321\n", "print(phone_book)" @@ -163,9 +219,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{123: 'blabla', True: 123.456, 'key': False, (123, 'abc'): 1000, 34.5: [0, 1, 1, 2, 3, 5]}\n" + ] + } + ], "source": [ "stupid_dict = {\n", " 123: \"blabla\",\n", @@ -189,9 +253,17 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 8, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{('Paul', 'McCartney'): 123456}\n" + ] + } + ], "source": [ "new_phone_book = {(\"Paul\", \"McCartney\"): 123456}\n", "print(new_phone_book)" @@ -199,9 +271,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "unhashable type: 'list'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[9], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m new_phone_book \u001b[38;5;241m=\u001b[39m {[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPaul\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMcCartney\u001b[39m\u001b[38;5;124m\"\u001b[39m]: \u001b[38;5;241m123456\u001b[39m}\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(new_phone_book)\n", + "\u001b[1;31mTypeError\u001b[0m: unhashable type: 'list'" + ] + } + ], "source": [ "new_phone_book = {[\"Paul\", \"McCartney\"]: 123456}\n", "print(new_phone_book)" @@ -218,9 +302,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 11, + "metadata": {}, + "outputs": [ + { + "ename": "KeyError", + "evalue": "'P. McCartney'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[11], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mdel\u001b[39;00m \u001b[43mphone_book\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mP. McCartney\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(phone_book)\n", + "\u001b[1;31mKeyError\u001b[0m: 'P. McCartney'" + ] + } + ], "source": [ "del phone_book[\"P. McCartney\"]\n", "print(phone_book)" @@ -237,9 +333,21 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "J. Lennon 987654321\n", + "G. Harrison 11342555\n", + "R. Starr 77788832\n", + "Y. Ono 5463333\n", + "B. Epstein 9998777\n" + ] + } + ], "source": [ "for name in phone_book:\n", " print(name, phone_book[name])" @@ -269,18 +377,35 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 13, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "5\n" + ] + } + ], "source": [ "print(len(phone_book))" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 14, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_keys(['J. Lennon', 'G. Harrison', 'R. Starr', 'Y. Ono', 'B. Epstein'])\n", + "['J. Lennon', 'G. Harrison', 'R. Starr', 'Y. Ono', 'B. Epstein']\n" + ] + } + ], "source": [ "print(phone_book.keys())\n", "print(list(phone_book.keys()))" @@ -288,18 +413,34 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 15, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[987654321, 11342555, 77788832, 5463333, 9998777]\n" + ] + } + ], "source": [ "print(list(phone_book.values()))" ] }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "dict_items([('J. Lennon', 987654321), ('G. Harrison', 11342555), ('R. Starr', 77788832), ('Y. Ono', 5463333), ('B. Epstein', 9998777)])\n" + ] + } + ], "source": [ "print(phone_book.items())" ] @@ -326,9 +467,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 17, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{'name': 'McCartney', 'firstname': 'Paul', 'subject': 'Music', 'musician': True, 'instruments': ['bass', 'guitar', 'piano'], 'bands': ['Beatles', 'Wings']}\n", + "McCartney\n" + ] + } + ], "source": [ "student = {\n", " \"name\": \"McCartney\",\n", @@ -354,9 +504,18 @@ }, { "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "{12345: 'Paul McCartney', 23456: 'John Lennon', 34567: 'George Harrison', 45678: 'Ringo Starr'}\n", + "George Harrison\n" + ] + } + ], "source": [ "students = {\n", " 12345: \"Paul McCartney\",\n", @@ -369,8 +528,10 @@ ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": null, "metadata": {}, + "outputs": [], "source": [ "# Exercise 1: Translation\n", "\n", @@ -381,10 +542,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 21, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "color_dict = {\n", + " 'red': 'rot',\n", + " 'green': 'grün',\n", + " 'blue': 'blau',\n", + " 'yellow': 'gelb'\n", + "}\n", + "#get input from user on a color in english then what it means in german\n", + "# Ask the user for another English color and its German translation\n", + "new_color_english = input(\"Enter an English color: \").strip().lower()\n", + "new_color_german = input(\"Enter its German translation: \").strip().lower()" + ] }, { "cell_type": "markdown", @@ -411,10 +583,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 23, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Updated dictionary of colors:\n", + "{'red': 'rot', 'green': 'grün', 'blue': 'blau', 'yellow': 'gelb'}\n" + ] + } + ], + "source": [ + "#add the pair to the dictionary \n", + "color_dict[new_color_english] = new_color_german\n", + "#print the results for the output \n", + "print(\"Updated dictionary of colors:\")\n", + "print(color_dict)" + ] }, { "cell_type": "markdown", @@ -429,11 +616,8 @@ ], "metadata": { "file_extension": ".py", - "interpreter": { - "hash": "ac59ebe37160ed0dfa835113d9b8498d9f09ceb179beaac4002f036b9467c963" - }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -447,7 +631,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -457,4 +641,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_3/w3u3.ipynb b/week_3/w3u3.ipynb index 2e96e46..6a8d592 100644 --- a/week_3/w3u3.ipynb +++ b/week_3/w3u3.ipynb @@ -39,9 +39,22 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 41, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1\n", + "2\n", + "4\n", + "8\n", + "16\n", + "32\n" + ] + } + ], "source": [ "numbers = [2, 4, 8, 16, 32, 64]\n", "for i in numbers:\n", @@ -69,9 +82,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 42, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Philosophy\n", + "Mechanical Engineering\n", + "Medicine\n" + ] + } + ], "source": [ "student_1 = (\"Dylan\", \"Bob\", 334455, \"Philosophy\")\n", "student_2 = (\"Cobain\", \"Kurt\", 987654, \"Mechanical Engineering\")\n", @@ -103,9 +126,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "334455 Philosophy\n", + "987654 Mechanical Engineering\n", + "123321 Medicine\n" + ] + } + ], "source": [ "student_1 = (\"Dylan\", \"Bob\", \"Philosophy\")\n", "student_2 = (\"Cobain\", \"Kurt\", \"Mechanical Engineering\")\n", @@ -144,9 +177,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 44, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('Dylan', 'Bob', 334455, 'Philosophy', {'Logic': 'A', 'Ethics': 'B'})\n", + "('Cobain', 'Kurt', 987654, 'Mechanical Engineering', {'Math': 'B'})\n", + "('Winehouse', 'Amy', 123321, 'Medicine', {'Math': 'B', 'Chemistry': 'C'})\n" + ] + } + ], "source": [ "s1 = (\"Dylan\", \"Bob\", 334455, \"Philosophy\", {\"Logic\": \"A\", \"Ethics\": \"B\"})\n", "s2 = (\"Cobain\", \"Kurt\", 987654, \"Mechanical Engineering\", {\"Math\": \"B\"})\n", @@ -185,7 +228,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ @@ -199,7 +242,13 @@ " (\"Parkinson\", \"Pansy\", 482103, \"pansy@hogwarts.wiz\", \"Dark Arts\"),\n", " (\"Malfoy\", \"Draco\", 492010, \"draco@hogwarts.wiz\", \"Defence Against the Dark Arts\"),\n", " (\"Thomas\", \"Dean\", 447924, \"dean.thomas@hogwarts.wiz\", \"Divination\"),\n", - "]" + " \n", + "]\n", + "last_name = input(\"Last Name: \")\n", + "first_name = input(\"First Name: \")\n", + "student_id = int(input(\"Student ID: \")) # Assuming Student ID is an integer\n", + "email = input(\"Email: \")\n", + "course = input(\"Course: \")" ] }, { @@ -215,10 +264,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 52, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "list_of_students = [\n", + " (\"Potter\", \"Harry\", 477264, \"harry@hogwarts.wiz\", \"Defence Against the Dark Arts\"),\n", + " (\"Weasley\", \"Ron\", 490134, \"ron@hogwarts.wiz\", \"Care of Magical Creatures\"),\n", + " (\"Granger\", \"Hermione\", 471617, \"hermione@hogwarts.wiz\", \"Alchemy\"),\n", + " (\"Creevey\", \"Colin\", 432646, \"colin@hogwarts.wiz\", \"Music\"),\n", + " (\"Finnigan\", \"Seamus\", 481989, \"seamus@hogwarts.wiz\", \"Ancient Studies\"),\n", + " (\"Abbott\", \"Hannah\", 488962, \"hannah@hogwarts.wiz\", \"Apparition\"),\n", + " (\"Parkinson\", \"Pansy\", 482103, \"pansy@hogwarts.wiz\", \"Dark Arts\"),\n", + " (\"Malfoy\", \"Draco\", 492010, \"draco@hogwarts.wiz\", \"Defence Against the Dark Arts\"),\n", + " (\"Thomas\", \"Dean\", 447924, \"dean.thomas@hogwarts.wiz\", \"Divination\"),\n", + "]#made list of students into dictionary-ID is the key and the rest is a tuple\n", + "students_dict = {student[2]: (student[0], student[1], student[3], student[4]) for student in list_of_students}\n" + ] }, { "cell_type": "markdown", @@ -237,6 +299,38 @@ "outputs": [], "source": [] }, + { + "cell_type": "code", + "execution_count": 53, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Student ID: 447924 -> {'last_name': 'Thomas', 'first_name': 'Dean', 'email': 'dean.thomas@hogwarts.wiz', 'course': 'Divination'}\n" + ] + } + ], + "source": [ + "#change tuple into dictionary\n", + "transformed_students = {}\n", + "\n", + "for student_id, student_info in students_dict.items():\n", + " student_dict = {\n", + " \"last_name\": student_info[0],\n", + " \"first_name\": student_info[1],\n", + " \"email\": student_info[2],\n", + " \"course\": student_info[3]\n", + " }\n", + " #added new info for the student id as the key\n", + "\n", + "transformed_students[student_id] = student_dict\n", + "for student_id, student_dict in transformed_students.items():\n", + " print(f\"Student ID: {student_id} -> {student_dict}\")\n", + "\n" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -271,7 +365,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -281,4 +375,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_3/w3u4.ipynb b/week_3/w3u4.ipynb index faec6d2..0fb51d3 100644 --- a/week_3/w3u4.ipynb +++ b/week_3/w3u4.ipynb @@ -11,9 +11,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Peter\n" + ] + }, + { + "ename": "KeyError", + "evalue": "3456", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28mdict\u001b[39m \u001b[38;5;241m=\u001b[39m {\u001b[38;5;241m1234\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPeter\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;241m2345\u001b[39m: \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mJane\u001b[39m\u001b[38;5;124m\"\u001b[39m}\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28mdict\u001b[39m[\u001b[38;5;241m1234\u001b[39m])\n\u001b[1;32m----> 3\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[38;5;28;43mdict\u001b[39;49m\u001b[43m[\u001b[49m\u001b[38;5;241;43m3456\u001b[39;49m\u001b[43m]\u001b[49m)\n", + "\u001b[1;31mKeyError\u001b[0m: 3456" + ] + } + ], "source": [ "dict = {1234: \"Peter\", 2345: \"Jane\"}\n", "print(dict[1234])\n", @@ -32,9 +51,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "A student with this matriculation number does not exist\n" + ] + } + ], "source": [ "dict_of_students = {\n", " 477264: (\"Potter\", \"Harry\", \"harry@hogwarts.wiz\", \"Defence Against the Dark Arts\"),\n", @@ -73,9 +100,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "For the matriculation number 7 the dictionary returned the following result: no matching student found for this matriculation number\n" + ] + } + ], "source": [ "input_num = int(input(\"Please enter matriculation number:\"))\n", "student = dict_of_students.get(\n", @@ -111,7 +146,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -121,4 +156,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_3/w3u5.ipynb b/week_3/w3u5.ipynb index 6fc9203..31054ff 100644 --- a/week_3/w3u5.ipynb +++ b/week_3/w3u5.ipynb @@ -57,9 +57,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "i\n" + ] + } + ], "source": [ "text = \"lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.\"\n", "letters = \"abcdefghijklmnopqrstuvwxyz\"\n", @@ -103,9 +111,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_3/w3u6.ipynb b/week_3/w3u6.ipynb index a970a62..0f7b7d8 100644 --- a/week_3/w3u6.ipynb +++ b/week_3/w3u6.ipynb @@ -54,7 +54,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -305,9 +305,23 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "KeyboardInterrupt", + "evalue": "Interrupted by user", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[6], line 7\u001b[0m\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m matnr \u001b[38;5;241m==\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m\"\u001b[39m:\n\u001b[0;32m 6\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[1;32m----> 7\u001b[0m name \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43minput\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mEnter name: \u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 8\u001b[0m firstname \u001b[38;5;241m=\u001b[39m \u001b[38;5;28minput\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mEnter first name: \u001b[39m\u001b[38;5;124m\"\u001b[39m)\n\u001b[0;32m 9\u001b[0m list_of_students\u001b[38;5;241m.\u001b[39mappend((matnr, name, firstname))\n", + "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\ipykernel\\kernelbase.py:1282\u001b[0m, in \u001b[0;36mKernel.raw_input\u001b[1;34m(self, prompt)\u001b[0m\n\u001b[0;32m 1280\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mraw_input was called, but this frontend does not support input requests.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 1281\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m StdinNotImplementedError(msg)\n\u001b[1;32m-> 1282\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_input_request\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 1283\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mstr\u001b[39;49m\u001b[43m(\u001b[49m\u001b[43mprompt\u001b[49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1284\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_parent_ident\u001b[49m\u001b[43m[\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1285\u001b[0m \u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget_parent\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mshell\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1286\u001b[0m \u001b[43m \u001b[49m\u001b[43mpassword\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m,\u001b[49m\n\u001b[0;32m 1287\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\ipykernel\\kernelbase.py:1325\u001b[0m, in \u001b[0;36mKernel._input_request\u001b[1;34m(self, prompt, ident, parent, password)\u001b[0m\n\u001b[0;32m 1322\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m:\n\u001b[0;32m 1323\u001b[0m \u001b[38;5;66;03m# re-raise KeyboardInterrupt, to truncate traceback\u001b[39;00m\n\u001b[0;32m 1324\u001b[0m msg \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInterrupted by user\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m-> 1325\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mKeyboardInterrupt\u001b[39;00m(msg) \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 1326\u001b[0m \u001b[38;5;28;01mexcept\u001b[39;00m \u001b[38;5;167;01mException\u001b[39;00m:\n\u001b[0;32m 1327\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mlog\u001b[38;5;241m.\u001b[39mwarning(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mInvalid Message:\u001b[39m\u001b[38;5;124m\"\u001b[39m, exc_info\u001b[38;5;241m=\u001b[39m\u001b[38;5;28;01mTrue\u001b[39;00m)\n", + "\u001b[1;31mKeyboardInterrupt\u001b[0m: Interrupted by user" + ] + } + ], "source": [ "list_of_students = []\n", "\n", @@ -360,10 +374,51 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Year 1: $210000.00\n", + "Year 2: $220500.00\n", + "Year 3: $231525.00\n", + "Year 4: $243101.25\n", + "Year 5: $255256.31\n", + "Year 6: $268019.13\n", + "Year 7: $281420.08\n", + "Year 8: $295491.09\n", + "Year 9: $310265.64\n", + "Year 10: $325778.93\n", + "Year 11: $342067.87\n", + "Year 12: $359171.27\n", + "Year 13: $377129.83\n", + "Year 14: $395986.32\n", + "Year 15: $415785.64\n", + "\n", + "The property value doubled in 15 years.\n" + ] + } + ], + "source": [ + "# Get user inputs\n", + "initial_value = float(input(\"What is the value of the property? \"))\n", + "percentage_increase = float(input(\"By what percentage does the value increase per year? \"))\n", + "\n", + "# Set the target value to double the starting value\n", + "target_value = initial_value * 2\n", + "current_value = initial_value\n", + "year = 0\n", + "\n", + "# Calculate the value for each year until it doubles\n", + "while current_value < target_value:\n", + " year += 1\n", + " current_value += current_value * (percentage_increase / 100)\n", + " print(f\"Year {year}: ${current_value:.2f}\")\n", + "\n", + "print(f\"\\nThe property value doubled in {year} years.\")\n" + ] } ], "metadata": { @@ -382,9 +437,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_4/Ipsum file b/week_4/Ipsum file new file mode 100644 index 0000000..82807a5 --- /dev/null +++ b/week_4/Ipsum file @@ -0,0 +1,7 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris +nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in +reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla +pariatur. Excepteur sint occaecat cupidatat non proident, sunt in +culpa qui officia deserunt mollit anim id est laborum. \ No newline at end of file diff --git a/week_4/key.txt b/week_4/key.txt new file mode 100644 index 0000000..b944734 --- /dev/null +++ b/week_4/key.txt @@ -0,0 +1,2 @@ +3 +4 diff --git a/week_4/letters.txt b/week_4/letters.txt new file mode 100644 index 0000000..0edb856 --- /dev/null +++ b/week_4/letters.txt @@ -0,0 +1,26 @@ +a +b +c +d +e +f +g +h +i +j +k +l +m +n +o +p +q +r +s +t +u +v +w +x +y +z diff --git a/week_4/new_file.txt b/week_4/new_file.txt new file mode 100644 index 0000000..9e0dd4d --- /dev/null +++ b/week_4/new_file.txt @@ -0,0 +1 @@ +Amanda loves Python! \ No newline at end of file diff --git a/week_4/numbers.txt b/week_4/numbers.txt new file mode 100644 index 0000000..c344d0a --- /dev/null +++ b/week_4/numbers.txt @@ -0,0 +1,100 @@ +0 +1 +2 +3 +4 +5 +6 +7 +8 +9 +10 +11 +12 +13 +14 +15 +16 +17 +18 +19 +20 +21 +22 +23 +24 +25 +26 +27 +28 +29 +30 +31 +32 +33 +34 +35 +36 +37 +38 +39 +40 +41 +42 +43 +44 +45 +46 +47 +48 +49 +50 +51 +52 +53 +54 +55 +56 +57 +58 +59 +60 +61 +62 +63 +64 +65 +66 +67 +68 +69 +70 +71 +72 +73 +74 +75 +76 +77 +78 +79 +80 +81 +82 +83 +84 +85 +86 +87 +88 +89 +90 +91 +92 +93 +94 +95 +96 +97 +98 +99 diff --git a/week_4/player1.txt b/week_4/player1.txt new file mode 100644 index 0000000..746e4a5 --- /dev/null +++ b/week_4/player1.txt @@ -0,0 +1,100 @@ +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R diff --git a/week_4/player2.txt b/week_4/player2.txt new file mode 100644 index 0000000..d21c498 --- /dev/null +++ b/week_4/player2.txt @@ -0,0 +1,100 @@ +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S +R +P +S diff --git a/week_4/public.txt b/week_4/public.txt new file mode 100644 index 0000000..eca4d48 --- /dev/null +++ b/week_4/public.txt @@ -0,0 +1,4 @@ +### +.#. +.#. +.# diff --git a/week_4/result.txt b/week_4/result.txt new file mode 100644 index 0000000..48cb40e --- /dev/null +++ b/week_4/result.txt @@ -0,0 +1,3 @@ +Player1 wins: 100 +Player2 wins: 0 +Draws: 0 diff --git a/week_4/results.txt b/week_4/results.txt new file mode 100644 index 0000000..2f6c05c --- /dev/null +++ b/week_4/results.txt @@ -0,0 +1,3 @@ +Player1 wins: 100 +Player2 wins: 0 +Draw2: 0 diff --git a/week_4/secret.txt b/week_4/secret.txt new file mode 100644 index 0000000..e71bb2c --- /dev/null +++ b/week_4/secret.txt @@ -0,0 +1,11 @@ +# +# +# +. +# +. +. +# +. +. +# diff --git a/week_4/students.txt b/week_4/students.txt new file mode 100644 index 0000000..4a14b3a --- /dev/null +++ b/week_4/students.txt @@ -0,0 +1,9 @@ +Potter, Harry, 477264, harry@hogwarts.wiz, Defence Against the Dark Arts, +Weasley, Ron, 490134, ron@hogwarts.wiz, Care of Magical Creatures, +Granger, Hermione, 471617, hermione@hogwarts.wiz, Alchemy, +Creevey, Colin, 432646, colin@hogwarts.wiz, Music, +Finnigan, Seamus, 481989, seamus@hogwarts.wiz, Ancient Studies, +Abbott, Hannah, 488962, hannah@hogwarts.wiz, Apparition, +Parkinson, Pansy, 482103, pansy@hogwarts.wiz, Dark Arts, +Malfoy, Draco, 492010, draco@hogwarts.wiz, Defence Against the Dark Arts, +Thomas, Dean, 447924, dean.thomas@hogwarts.wiz, Divination, diff --git a/week_4/w4bonus.ipynb b/week_4/w4bonus.ipynb index 73d1cf4..40b8211 100644 --- a/week_4/w4bonus.ipynb +++ b/week_4/w4bonus.ipynb @@ -77,6 +77,90 @@ " file.write(\"Draw2: \" + str(results[2]) + \"\\n\")\n", " " ] + }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "player1.txt and player2.txt created with predefined moves.\n" + ] + } + ], + "source": [ + "def create_file(filename, moves):\n", + " with open(filename, 'w') as file:\n", + " for move in moves:\n", + " file.write(f\"{move}\\n\")\n", + "\n", + "# defines the moves of the players\n", + "player1_moves = ['R', 'P', 'S'] * 33 + ['R'] # 100 moves\n", + "player2_moves = ['S', 'R', 'P'] * 33 + ['S'] # 100 moves\n", + "\n", + "# create both files at one time\n", + "create_file('player1.txt', player1_moves)\n", + "create_file('player2.txt', player2_moves)\n", + "\n", + "print(\"player1.txt and player2.txt created with predefined moves.\")\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "def read_moves(filename):\n", + " with open(filename, 'r') as file:\n", + " moves = [line.strip() for line in file]\n", + " return moves\n", + "\n", + "def determine_winner(move1, move2):\n", + " if move1 == move2:\n", + " return 'draw'\n", + " elif (move1 == 'R' and move2 == 'S') or (move1 == 'S' and move2 == 'P') or (move1 == 'P' and move2 == 'R'):\n", + " return 'player1'\n", + " else:\n", + " return 'player2'\n", + "\n", + "def main():\n", + " # r3eads the moves # this has to happen 1st \n", + " player1_moves = read_moves('player1.txt')\n", + " player2_moves = read_moves('player2.txt')\n", + "\n", + " # makes sure both players have 100 moves\n", + " if len(player1_moves) != 100 or len(player2_moves) != 100:\n", + " print(\"Both players must have exactly 100 moves.\")\n", + " return\n", + "\n", + " # starts couting before compare\n", + " player1_wins = 0\n", + " player2_wins = 0\n", + " draws = 0\n", + "\n", + " # compares and then counts the moves\n", + " for move1, move2 in zip(player1_moves, player2_moves):\n", + " result = determine_winner(move1, move2)\n", + " if result == 'player1':\n", + " player1_wins += 1\n", + " elif result == 'player2':\n", + " player2_wins += 1\n", + " else:\n", + " draws += 1\n", + "\n", + " # writes the results to my result.txt file\n", + " with open('result.txt', 'w') as result_file:\n", + " result_file.write(f\"Player1 wins: {player1_wins}\\n\")\n", + " result_file.write(f\"Player2 wins: {player2_wins}\\n\")\n", + " result_file.write(f\"Draws: {draws}\\n\")\n", + "\n", + "if __name__ == \"__main__\":\n", + " main()\n" + ] } ], "metadata": { @@ -95,9 +179,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/week_4/w4solution.ipynb b/week_4/w4solution.ipynb index 187b4f1..b4beee4 100644 --- a/week_4/w4solution.ipynb +++ b/week_4/w4solution.ipynb @@ -45,9 +45,22 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "FileNotFoundError", + "evalue": "[Errno 2] No such file or directory: 'key.txt'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[1], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m size \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mkey.txt\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mr\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m file:\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m line \u001b[38;5;129;01min\u001b[39;00m file:\n\u001b[0;32m 4\u001b[0m line \u001b[38;5;241m=\u001b[39m line\u001b[38;5;241m.\u001b[39mstrip()\n", + "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\IPython\\core\\interactiveshell.py:324\u001b[0m, in \u001b[0;36m_modified_open\u001b[1;34m(file, *args, **kwargs)\u001b[0m\n\u001b[0;32m 317\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m file \u001b[38;5;129;01min\u001b[39;00m {\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m}:\n\u001b[0;32m 318\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[0;32m 319\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIPython won\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt let you open fd=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfile\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m by default \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 320\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mas it is likely to crash IPython. If you know what you are doing, \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 321\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myou can use builtins\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m open.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 322\u001b[0m )\n\u001b[1;32m--> 324\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mio_open\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'key.txt'" + ] + } + ], "source": [ "size = []\n", "with open(\"key.txt\", \"r\") as file:\n", @@ -80,6 +93,252 @@ " line += \"\\n\"\n", " file.write(line)" ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "ename": "FileNotFoundError", + "evalue": "[Errno 2] No such file or directory: 'key.txt'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[2], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m size \u001b[38;5;241m=\u001b[39m []\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mkey.txt\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mr\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m \u001b[38;5;28;01mas\u001b[39;00m file:\n\u001b[0;32m 3\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m line \u001b[38;5;129;01min\u001b[39;00m file:\n\u001b[0;32m 4\u001b[0m line \u001b[38;5;241m=\u001b[39m line\u001b[38;5;241m.\u001b[39mstrip()\n", + "File \u001b[1;32m~\\AppData\\Roaming\\Python\\Python313\\site-packages\\IPython\\core\\interactiveshell.py:324\u001b[0m, in \u001b[0;36m_modified_open\u001b[1;34m(file, *args, **kwargs)\u001b[0m\n\u001b[0;32m 317\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m file \u001b[38;5;129;01min\u001b[39;00m {\u001b[38;5;241m0\u001b[39m, \u001b[38;5;241m1\u001b[39m, \u001b[38;5;241m2\u001b[39m}:\n\u001b[0;32m 318\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mValueError\u001b[39;00m(\n\u001b[0;32m 319\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mIPython won\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124mt let you open fd=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mfile\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m by default \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 320\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mas it is likely to crash IPython. If you know what you are doing, \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 321\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myou can use builtins\u001b[39m\u001b[38;5;124m'\u001b[39m\u001b[38;5;124m open.\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 322\u001b[0m )\n\u001b[1;32m--> 324\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43mio_open\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfile\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43margs\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwargs\u001b[49m\u001b[43m)\u001b[49m\n", + "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'key.txt'" + ] + } + ], + "source": [ + "size = []\n", + "with open(\"key.txt\", \"r\") as file:\n", + " for line in file:\n", + " line = line.strip()\n", + " line = int(line)\n", + " size.append(line)\n", + "\n", + "col = size[0]\n", + "row = size[1]\n", + "\n", + "chars = []\n", + "with open(\"secret.txt\", \"r\") as file:\n", + " for line in file:\n", + " line = line.strip()\n", + " chars.append(line)\n", + "\n", + "count = 0 # has to start at 0\n", + "public = []\n", + "line = \"\"\n", + "\n", + "for char in chars:\n", + " line += char\n", + " count += 1\n", + " if count == col:\n", + " public.append(line)\n", + " line = \"\"\n", + " count = 0 # start count at 0 for next linbe\n", + "\n", + "# check for leftover letters\n", + "if line:\n", + " public.append(line)\n", + "\n", + "with open(\"public.txt\", \"w\") as file:\n", + " for line in public:\n", + " file.write(line + \"\\n\") # new line\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Created key.txt and secret.txt with sample data.\n", + "public.txt has been created with the grid content.\n" + ] + } + ], + "source": [ + "import os #lets me create files on my machine \n", + "\n", + "def create_files():\n", + " # create key.txt\n", + " with open(\"key.txt\", \"w\") as key_file:\n", + " key_file.write(\"5\\n\") # number of columns\n", + " key_file.write(\"4\\n\") # number of rows\n", + "\n", + " # create secret.txt\n", + " with open(\"secret.txt\", \"w\") as secret_file:\n", + " characters = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\",\n", + " \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\"]\n", + " for char in characters:\n", + " secret_file.write(f\"{char}\\n\")\n", + "\n", + "def read_key():\n", + " size = []\n", + " with open(\"key.txt\", \"r\") as file:\n", + " for line in file:\n", + " line = line.strip()\n", + " line = int(line)\n", + " size.append(line)\n", + " return size[0], size[1]\n", + "\n", + "def read_secret():\n", + " chars = []\n", + " with open(\"secret.txt\", \"r\") as file:\n", + " for line in file:\n", + " line = line.strip()\n", + " chars.append(line)\n", + " return chars\n", + "\n", + "def fill_grid(chars, col):\n", + " public = []\n", + " line = \"\"\n", + " count = 0\n", + "\n", + " for char in chars:\n", + " line += char\n", + " count += 1\n", + " if count == col:\n", + " public.append(line)\n", + " line = \"\"\n", + " count = 0\n", + "\n", + " # check for remianing characters\n", + " if line:\n", + " public.append(line)\n", + "\n", + " return public\n", + "\n", + "def write_public(grid):\n", + " with open(\"public.txt\", \"w\") as file:\n", + " for line in grid:\n", + " file.write(line + \"\\n\") # new line each time\n", + "\n", + "def main():\n", + " # creates files that I dont have\n", + " if not os.path.exists(\"key.txt\") or not os.path.exists(\"secret.txt\"):\n", + " create_files()\n", + " print(\"Created key.txt and secret.txt with sample data.\")\n", + "\n", + " # reads the key and the secret file \n", + " col, row = read_key()\n", + " chars = read_secret()\n", + "\n", + " # fills grid\n", + " public = fill_grid(chars, col)\n", + "\n", + " # writes to file \n", + " write_public(public)\n", + " \n", + " print(\"public.txt has been created with the grid content.\")\n", + "\n", + "if __name__ == \"__main__\":\n", + " main()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Created or updated key.txt and secret.txt with sample data.\n", + "public.txt has been created with the grid content.\n" + ] + } + ], + "source": [ + "import os #creates files on my computer\n", + "\n", + "def create_files():\n", + " # create key.txt with 3 columns and 4 rows\n", + " with open(\"key.txt\", \"w\") as key_file:\n", + " key_file.write(\"3\\n\") # numbers of columns\n", + " key_file.write(\"4\\n\") # number 0of rows\n", + "\n", + " # create secret txt\n", + " with open(\"secret.txt\", \"w\") as secret_file:\n", + " characters = [\n", + " \"#\", \"#\", \"#\",\n", + " \".\", \"#\",\n", + " \".\", \".\",\n", + " \"#\", \".\",\n", + " \".\", \"#\"\n", + " ]\n", + " for char in characters:\n", + " secret_file.write(f\"{char}\\n\")\n", + "\n", + "def read_key():\n", + " size = []\n", + " with open(\"key.txt\", \"r\") as file:\n", + " for line in file:\n", + " line = line.strip()\n", + " line = int(line)\n", + " size.append(line)\n", + " return size[0], size[1]\n", + "\n", + "def read_secret():\n", + " chars = []\n", + " with open(\"secret.txt\", \"r\") as file:\n", + " for line in file:\n", + " line = line.strip()\n", + " chars.append(line)\n", + " return chars\n", + "\n", + "def fill_grid(chars, col):\n", + " public = []\n", + " line = \"\"\n", + " count = 0\n", + "\n", + " for char in chars:\n", + " line += char\n", + " count += 1\n", + " if count == col:\n", + " public.append(line)\n", + " line = \"\"\n", + " count = 0\n", + "\n", + " # check for remaining characters\n", + " if line:\n", + " public.append(line)\n", + "\n", + " return public\n", + "\n", + "def write_public(grid):\n", + " with open(\"public.txt\", \"w\") as file:\n", + " for line in grid:\n", + " file.write(line + \"\\n\") # write each line w new line\n", + "\n", + "def main():\n", + " # create file w sample data \n", + " create_files()\n", + " print(\"Created or updated key.txt and secret.txt with sample data.\")\n", + "\n", + " # read the key and secret file\n", + " col, row = read_key()\n", + " chars = read_secret()\n", + "\n", + " # fill grid\n", + " public = fill_grid(chars, col)\n", + "\n", + " # write to public\n", + " write_public(public)\n", + " \n", + " print(\"public.txt has been created with the grid content.\")\n", + "\n", + "if __name__ == \"__main__\":\n", + " main()\n" + ] } ], "metadata": { @@ -98,9 +357,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/week_4/w4u1.ipynb b/week_4/w4u1.ipynb index 6ac957f..40560a0 100644 --- a/week_4/w4u1.ipynb +++ b/week_4/w4u1.ipynb @@ -50,9 +50,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('amanda wilson', 'amanda', '6068883434', '56')\n" + ] + } + ], "source": [ "name = input(\"Please enter name: \")\n", "first_name = input(\"Please enter first name: \")\n", @@ -81,7 +89,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -91,4 +99,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_4/w4u2.ipynb b/week_4/w4u2.ipynb index c5bf0ee..c796710 100644 --- a/week_4/w4u2.ipynb +++ b/week_4/w4u2.ipynb @@ -74,7 +74,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -85,6 +85,15 @@ "file.close()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#file was created " + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -96,7 +105,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -107,6 +116,15 @@ "file.close()" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#if i delete it it wont open. if i save text it opened new txt file" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -117,6 +135,15 @@ "happened?" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#it did not save it " + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -131,18 +158,291 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n", + "\n", + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n", + "\n", + "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n", + "\n", + "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in\n", + "\n", + "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\n", + "\n", + "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in\n", + "\n", + "culpa qui officia deserunt mollit anim id est laborum.\n" + ] + } + ], "source": [ "# open file\n", - "with open(\"lorem_ipsum.txt\", \"r\") as file:\n", + "with open(\"w4u2ipsum.txt\", \"r\") as file:\n", " # read file line by line and output the lines\n", " for line in file:\n", " print(line)\n", "\n", "# file will be closed automatically" ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#after modifying name of text file cell ran as designed" + ] + }, + { + "cell_type": "code", + "execution_count": 14, + "metadata": {}, + "outputs": [], + "source": [ + "# Program 1=edit \n", + "# Using the with statement to open a file for writing\n", + "with open(\"new_file.txt\", \"w\") as file:\n", + " # modify the file or enter text\n", + " file.write(\"Amanda loves Python!\") \n", + "# The file is automatically closed after this\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "#the above experiment Program 1=edit created the text file saved my text and closed!" + ] + }, + { + "cell_type": "code", + "execution_count": 16, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0\n", + "\n", + "1\n", + "\n", + "2\n", + "\n", + "3\n", + "\n", + "4\n", + "\n", + "5\n", + "\n", + "6\n", + "\n", + "7\n", + "\n", + "8\n", + "\n", + "9\n", + "\n", + "10\n", + "\n", + "11\n", + "\n", + "12\n", + "\n", + "13\n", + "\n", + "14\n", + "\n", + "15\n", + "\n", + "16\n", + "\n", + "17\n", + "\n", + "18\n", + "\n", + "19\n", + "\n", + "20\n", + "\n", + "21\n", + "\n", + "22\n", + "\n", + "23\n", + "\n", + "24\n", + "\n", + "25\n", + "\n", + "26\n", + "\n", + "27\n", + "\n", + "28\n", + "\n", + "29\n", + "\n", + "30\n", + "\n", + "31\n", + "\n", + "32\n", + "\n", + "33\n", + "\n", + "34\n", + "\n", + "35\n", + "\n", + "36\n", + "\n", + "37\n", + "\n", + "38\n", + "\n", + "39\n", + "\n", + "40\n", + "\n", + "41\n", + "\n", + "42\n", + "\n", + "43\n", + "\n", + "44\n", + "\n", + "45\n", + "\n", + "46\n", + "\n", + "47\n", + "\n", + "48\n", + "\n", + "49\n", + "\n", + "50\n", + "\n", + "51\n", + "\n", + "52\n", + "\n", + "53\n", + "\n", + "54\n", + "\n", + "55\n", + "\n", + "56\n", + "\n", + "57\n", + "\n", + "58\n", + "\n", + "59\n", + "\n", + "60\n", + "\n", + "61\n", + "\n", + "62\n", + "\n", + "63\n", + "\n", + "64\n", + "\n", + "65\n", + "\n", + "66\n", + "\n", + "67\n", + "\n", + "68\n", + "\n", + "69\n", + "\n", + "70\n", + "\n", + "71\n", + "\n", + "72\n", + "\n", + "73\n", + "\n", + "74\n", + "\n", + "75\n", + "\n", + "76\n", + "\n", + "77\n", + "\n", + "78\n", + "\n", + "79\n", + "\n", + "80\n", + "\n", + "81\n", + "\n", + "82\n", + "\n", + "83\n", + "\n", + "84\n", + "\n", + "85\n", + "\n", + "86\n", + "\n", + "87\n", + "\n", + "88\n", + "\n", + "89\n", + "\n", + "90\n", + "\n", + "91\n", + "\n", + "92\n", + "\n", + "93\n", + "\n", + "94\n", + "\n", + "95\n", + "\n", + "96\n", + "\n", + "97\n", + "\n", + "98\n", + "\n", + "99\n", + "\n", + "100\n" + ] + } + ], + "source": [ + "# experimented with numbers file and the cell ran that file as well\n", + "with open(\"w4u2nums.txt\", \"r\") as file:\n", + " # read file line by line and output the lines\n", + " for line in file:\n", + " print(line)" + ] } ], "metadata": { @@ -162,7 +462,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -172,4 +472,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_4/w4u2ipsum_copy.txt b/week_4/w4u2ipsum_copy.txt new file mode 100644 index 0000000..82807a5 --- /dev/null +++ b/week_4/w4u2ipsum_copy.txt @@ -0,0 +1,7 @@ +Lorem ipsum dolor sit amet, consectetur adipiscing elit, +sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. +Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris +nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in +reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla +pariatur. Excepteur sint occaecat cupidatat non proident, sunt in +culpa qui officia deserunt mollit anim id est laborum. \ No newline at end of file diff --git a/week_4/w4u3.ipynb b/week_4/w4u3.ipynb index bbf933d..ff34ba0 100644 --- a/week_4/w4u3.ipynb +++ b/week_4/w4u3.ipynb @@ -12,12 +12,32 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n", + "\n", + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n", + "\n", + "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n", + "\n", + "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in\n", + "\n", + "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\n", + "\n", + "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in\n", + "\n", + "culpa qui officia deserunt mollit anim id est laborum.\n" + ] + } + ], "source": [ "# open file\n", - "with open(\"lorem_ipsum.txt\", \"r\") as file:\n", + "with open(\"w4u2ipsum.txt\", \"r\") as file:\n", " # read file line by line and output the lines\n", " for line in file:\n", " print(line)" @@ -43,12 +63,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n", + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n", + "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n", + "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in\n", + "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\n", + "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in\n", + "culpa qui officia deserunt mollit anim id est laborum.\n" + ] + } + ], "source": [ "# Open file\n", - "with open(\"lorem_ipsum.txt\", \"r\") as file:\n", + "with open(\"w4u2ipsum.txt\", \"r\") as file:\n", " # read file line by line, strip from and output the lines\n", " for line in file:\n", " line = line.strip()\n", @@ -65,12 +99,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "First round\n", + "Lorem ipsum dolor sit amet, consectetur adipiscing elit,\n", + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\n", + "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\n", + "nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in\n", + "reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\n", + "pariatur. Excepteur sint occaecat cupidatat non proident, sunt in\n", + "culpa qui officia deserunt mollit anim id est laborum.\n", + "Second round\n" + ] + } + ], "source": [ "# open file\n", - "with open(\"lorem_ipsum.txt\", \"r\") as file:\n", + "with open(\"w4u2ipsum.txt\", \"r\") as file:\n", " # read file line by line and print the lines\n", " print(\"First round\")\n", " for line in file:\n", @@ -105,12 +155,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 10, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['Lorem ipsum dolor sit amet, consectetur adipiscing elit,\\n', 'sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.\\n', 'Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris\\n', 'nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in\\n', 'reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla\\n', 'pariatur. Excepteur sint occaecat cupidatat non proident, sunt in\\n', 'culpa qui officia deserunt mollit anim id est laborum.']\n" + ] + } + ], "source": [ "# Open file\n", - "with open(\"lorem_ipsum.txt\", \"r\") as file:\n", + "with open(\"w4u2ipsum.txt\", \"r\") as file:\n", " # read file in one go\n", " line = file.readlines()\n", " print(line)" @@ -133,10 +191,30 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The sum of the numbers is: 5050\n" + ] + } + ], + "source": [ + "# Program to read numbers from the nunbs file and output the sum\n", + "\n", + "total_sum = 0\n", + "\n", + "# using with to make sure it closes \n", + "with open(\"w4u2nums.txt\", \"r\") as file:\n", + " for line in file:\n", + " total_sum += int(line.strip()) # change each line to an integer and then to the total\n", + "\n", + "# Output the result\n", + "print(\"The sum of the numbers is:\", total_sum)\n" + ] } ], "metadata": { @@ -156,7 +234,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -166,4 +244,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_4/w4u4.ipynb b/week_4/w4u4.ipynb index f7c33aa..f2109fc 100644 --- a/week_4/w4u4.ipynb +++ b/week_4/w4u4.ipynb @@ -11,7 +11,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], "source": [ @@ -21,6 +21,40 @@ " file.write(line)" ] }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "ename": "TypeError", + "evalue": "write() argument must be str, not int", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mTypeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[2], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mwith\u001b[39;00m \u001b[38;5;28mopen\u001b[39m(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnumbers.txt\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mw\u001b[39m\u001b[38;5;124m\"\u001b[39m) \u001b[38;5;28;01mas\u001b[39;00m file:\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m i \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m100\u001b[39m):\n\u001b[1;32m----> 3\u001b[0m \u001b[43mfile\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mwrite\u001b[49m\u001b[43m(\u001b[49m\u001b[43mi\u001b[49m\u001b[43m)\u001b[49m \n", + "\u001b[1;31mTypeError\u001b[0m: write() argument must be str, not int" + ] + } + ], + "source": [ + "with open(\"numbers.txt\", \"w\") as file:\n", + " for i in range(100):\n", + " file.write(i) #this produces error since its a integer & not a string\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "with open(\"numbers.txt\", \"w\") as file:\n", + " for i in range(100):\n", + " file.write(str(i)) #this produced the numbers all together with no space or structure\n" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -44,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ @@ -93,9 +127,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "a\n", + "b\n" + ] + } + ], "source": [ "### Task: Writing letters from a-z to a file test cell\n", "letter = chr(97)\n", @@ -106,10 +149,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# Program to write letters from a to z into a file\n", + "\n", + "with open(\"letters.txt\", \"w\") as file:\n", + " for i in range(26): # 26 letters in the English alphabet\n", + " letter = chr(97 + i) # 97 is the ASCII value for 'a'\n", + " file.write(letter + \"\\n\") # Write the letter followed by a newline\n" + ] }, { "cell_type": "markdown", @@ -123,10 +173,49 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# file copy program\n", + "with open(\"w4u2ipsum.txt\", \"r\") as original_file:\n", + " content = original_file.read() # Read the entire content of the file\n", + "\n", + "with open(\"w4u2ipsum_copy.txt\", \"w\") as copy_file:\n", + " copy_file.write(content) # create new file \n" + ] + }, + { + "cell_type": "code", + "execution_count": 12, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "File 'w4u2ipsum.txt' has been copied to 'Ipsum file '.\n" + ] + } + ], + "source": [ + "# extended file copy program with user input\n", + "source_file_name = input(\"Enter the name of the file to be copied: \")\n", + "# ask user the name of the new file\n", + "destination_file_name = input(\"Enter the name of the new file: \")\n", + "\n", + "# copy file\n", + "try:\n", + " with open(source_file_name, \"r\") as original_file:\n", + " content = original_file.read() # read file\n", + "\n", + " with open(destination_file_name, \"w\") as copy_file:\n", + " copy_file.write(content) # copies file \n", + "\n", + " print(f\"File '{source_file_name}' has been copied to '{destination_file_name}'.\")\n", + "except FileNotFoundError:\n", + " print(f\"Error: The file '{source_file_name}' does not exist.\")\n" + ] } ], "metadata": { @@ -146,7 +235,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -156,4 +245,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_4/w4u5.ipynb b/week_4/w4u5.ipynb index bcacc40..072e232 100644 --- a/week_4/w4u5.ipynb +++ b/week_4/w4u5.ipynb @@ -13,9 +13,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Simple output\n", + "10 is a number\n", + "10 times 20 is 200\n" + ] + } + ], "source": [ "x = 10\n", "y = 20\n", @@ -53,9 +63,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "192.168.1.1\n", + "abcdefghi\n" + ] + } + ], "source": [ "print(192, 168, 1, 1, sep=\".\")\n", "print(\"abc\", \"def\", \"ghi\", sep=\"\")" @@ -76,9 +95,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 times 20 is 200\n" + ] + } + ], "source": [ "print(f\"{x} times {y} is {x*y}\")" ] @@ -93,9 +120,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Why did you enter 5 into this program?\n" + ] + } + ], "source": [ "print(f\"Why did you enter {input()} into this program?\")" ] @@ -117,10 +152,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "1 2 3 4 5 6 7 8 9 10 \n", + "2 4 6 8 10 12 14 16 18 20 \n", + "3 6 9 12 15 18 21 24 27 30 \n", + "4 8 12 16 20 24 28 32 36 40 \n", + "5 10 15 20 25 30 35 40 45 50 \n", + "6 12 18 24 30 36 42 48 54 60 \n", + "7 14 21 28 35 42 49 56 63 70 \n", + "8 16 24 32 40 48 56 64 72 80 \n", + "9 18 27 36 45 54 63 72 81 90 \n", + "10 20 30 40 50 60 70 80 90 100 \n" + ] + } + ], + "source": [ + "\n", + "# 1 loop for the first factor (1 to 10)\n", + "for i in range(1, 11):\n", + " # another loop for the second factor (1 to 10)\n", + " for j in range(1, 11):\n", + " # calculate \n", + " product = i * j\n", + " print(product, end=' ')\n", + " # move to new line w each row\n", + " print()\n" + ] }, { "cell_type": "markdown", @@ -134,9 +197,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Dining Table Count: 3 Price: 199.90 Total: 599.70\n", + "Chair Count: 12 Price: 39.59 Total: 475.08\n", + "Shelf Count: 5 Price: 9.90 Total: 49.50\n" + ] + } + ], "source": [ "products = [(\"Dining Table\", 3, 199.90), (\"Chair\", 12, 39.59), (\"Shelf\", 5, 9.90)]\n", "\n", @@ -167,16 +240,46 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + " 1 2 3 4 5 6 7 8 9 10 \n", + " 2 4 6 8 10 12 14 16 18 20 \n", + " 3 6 9 12 15 18 21 24 27 30 \n", + " 4 8 12 16 20 24 28 32 36 40 \n", + " 5 10 15 20 25 30 35 40 45 50 \n", + " 6 12 18 24 30 36 42 48 54 60 \n", + " 7 14 21 28 35 42 49 56 63 70 \n", + " 8 16 24 32 40 48 56 64 72 80 \n", + " 9 18 27 36 45 54 63 72 81 90 \n", + " 10 20 30 40 50 60 70 80 90 100 \n" + ] + } + ], + "source": [ + "\n", + "# define how many columns there is\n", + "num_columns = 10\n", + "\n", + "# first loop (1 to 10)\n", + "for i in range(1, num_columns + 1):\n", + " # second loop (1 to 10)\n", + " for j in range(1, num_columns + 1):\n", + " # align to the right hand side with a space of 4 in between\n", + " print(f\"{i * j:>4}\", end=' ') # prints the prettier output \n", + " # moves on to the nesxt line each time\n", + " print()\n" + ] } ], "metadata": { "file_extension": ".py", "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -190,7 +293,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" }, "mimetype": "text/x-python", "name": "python", @@ -200,4 +303,4 @@ }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_5/w5bonus.ipynb b/week_5/w5bonus.ipynb index e32ceb0..429a242 100644 --- a/week_5/w5bonus.ipynb +++ b/week_5/w5bonus.ipynb @@ -31,9 +31,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]\n" + ] + } + ], "source": [ "def isprime(cand):\n", " for i in range(2, cand):\n", @@ -70,9 +78,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/week_5/w5solution.ipynb b/week_5/w5solution.ipynb index 9580494..b309fd5 100644 --- a/week_5/w5solution.ipynb +++ b/week_5/w5solution.ipynb @@ -61,9 +61,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "gygkcz if fqrlyb nvahwwrll\n" + ] + } + ], "source": [ "def encrypt_letter(letter, shift):\n", " abc = \"abcdefghijklmnopqrstuvwxyz\"\n", @@ -126,9 +134,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 4 -} \ No newline at end of file +} diff --git a/week_5/w5u1.ipynb b/week_5/w5u1.ipynb index b1aa9dc..d59f010 100644 --- a/week_5/w5u1.ipynb +++ b/week_5/w5u1.ipynb @@ -35,9 +35,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Hallo Christian\n", + "Hallo Stephan\n", + "Hallo Lukas\n" + ] + } + ], "source": [ "names = [\"Christian\", \"Stephan\", \"Lukas\"]\n", "\n", @@ -77,7 +87,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -99,9 +109,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "42\n", + "Hello Hello \n" + ] + } + ], "source": [ "d = double(21)\n", "print(d)\n", @@ -150,9 +169,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "May the force be with you, Luke\n", + "May the force be with you, Christian\n" + ] + } + ], "source": [ "def greet(name):\n", " return \"May the force be with you, \" + name\n", @@ -209,20 +237,91 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[1;31mSignature:\u001b[0m \u001b[0mdouble\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mx\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mDocstring:\u001b[0m Doubles the value x\n", + "\u001b[1;31mFile:\u001b[0m c:\\users\\amand\\appdata\\local\\temp\\ipykernel_2000\\3096853178.py\n", + "\u001b[1;31mType:\u001b[0m function" + ] + } + ], "source": [ - "double?" + "double?\n" + ] + }, + { + "cell_type": "code", + "execution_count": 9, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[1;31mSignature:\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msep\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m' '\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'\\n'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfile\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mflush\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mDocstring:\u001b[0m\n", + "Prints the values to a stream, or to sys.stdout by default.\n", + "\n", + "sep\n", + " string inserted between values, default a space.\n", + "end\n", + " string appended after the last value, default a newline.\n", + "file\n", + " a file-like object (stream); defaults to the current sys.stdout.\n", + "flush\n", + " whether to forcibly flush the stream.\n", + "\u001b[1;31mType:\u001b[0m builtin_function_or_method" + ] + } + ], + "source": [ + "print?" + ] + }, + { + "cell_type": "code", + "execution_count": 10, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[1;31mInit signature:\u001b[0m \u001b[0mint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m/\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mDocstring:\u001b[0m \n", + "int([x]) -> integer\n", + "int(x, base=10) -> integer\n", + "\n", + "Convert a number or string to an integer, or return 0 if no arguments\n", + "are given. If x is a number, return x.__int__(). For floating-point\n", + "numbers, this truncates towards zero.\n", + "\n", + "If x is not a number or if base is given, then x must be a string,\n", + "bytes, or bytearray instance representing an integer literal in the\n", + "given base. The literal can be preceded by '+' or '-' and be surrounded\n", + "by whitespace. The base defaults to 10. Valid bases are 0 and 2-36.\n", + "Base 0 means to interpret the base from the string as an integer literal.\n", + ">>> int('0b100', base=0)\n", + "4\n", + "\u001b[1;31mType:\u001b[0m type\n", + "\u001b[1;31mSubclasses:\u001b[0m bool, IntEnum, IntFlag, _NamedIntConstant, _ZeroSentinel, Handle" + ] + } + ], + "source": [ + "int?\n" ] } ], "metadata": { - "interpreter": { - "hash": "9fd0e282e2343d8b38b390b803aabc7fcea80a18eee8e5bd23ce64f6435b30a1" - }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -236,9 +335,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_5/w5u2.ipynb b/week_5/w5u2.ipynb index b8a34b8..0cf088f 100644 --- a/week_5/w5u2.ipynb +++ b/week_5/w5u2.ipynb @@ -15,9 +15,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No, I'm your father!\n", + "None\n" + ] + } + ], "source": [ "def print_greeting():\n", " print(\"No, I'm your father!\")\n", @@ -37,9 +46,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No, I'm your father!\n" + ] + } + ], "source": [ "def famous_quote():\n", " return \"No, I'm your father!\"\n", @@ -58,9 +75,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the Answer to Life, The Universe, and Everything? 42\n" + ] + } + ], "source": [ "def the_answer_to_everything():\n", " return 42\n", @@ -74,9 +99,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "🐍\n" + ] + } + ], "source": [ "def is_python_the_best_programming_language():\n", " return True\n", @@ -95,9 +128,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "I'm listening to Ramones\n", + "I'm listening to Leave Home\n", + "I'm listening to Rocket to Russia\n", + "I'm listening to Road to Ruin\n" + ] + } + ], "source": [ "def ramones_records():\n", " return [\"Ramones\", \"Leave Home\", \"Rocket to Russia\", \"Road to Ruin\"]\n", @@ -118,9 +162,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "No, I'm your father!\n" + ] + } + ], "source": [ "def famous_quote():\n", " return \"No, I'm your father!\"\n", @@ -150,9 +202,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_5/w5u3.ipynb b/week_5/w5u3.ipynb index cdfafed..cf3650d 100644 --- a/week_5/w5u3.ipynb +++ b/week_5/w5u3.ipynb @@ -30,9 +30,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "What is the Answer to Life, The Universe, and Everything? 42\n", + "What is the sum of 39 and 3? 42\n" + ] + } + ], "source": [ "def the_answer_to_everything():\n", " return 42\n", @@ -68,10 +77,28 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "def is_palindrome(s):\n", + " \"\"\"\n", + " check if the given string is a palindrome.\n", + "\n", + " A palindrome is a word, phrase, or number that reads the same backward as forward.\n", + " This function ignores case.\n", + "\n", + " Parameters:\n", + " s (str): The string to check.\n", + "\n", + " Returns:\n", + " bool: True if s is a palindrome, False otherwise.\n", + " \"\"\"\n", + " # Normalize the string by converting it to lowercase\n", + " normalized_string = s.lower()\n", + " # Check if the string is the same forwards and backwards\n", + " return normalized_string == normalized_string[::-1]\n" + ] }, { "cell_type": "markdown", @@ -87,9 +114,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n", + "15\n" + ] + } + ], "source": [ "def multiply_with_factor(number, factor=2):\n", " return number * factor\n", @@ -114,9 +150,29 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "\u001b[1;31mSignature:\u001b[0m \u001b[0mprint\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m*\u001b[0m\u001b[0margs\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0msep\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m' '\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mend\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m'\\n'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mfile\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mNone\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mflush\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mFalse\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n", + "\u001b[1;31mDocstring:\u001b[0m\n", + "Prints the values to a stream, or to sys.stdout by default.\n", + "\n", + "sep\n", + " string inserted between values, default a space.\n", + "end\n", + " string appended after the last value, default a newline.\n", + "file\n", + " a file-like object (stream); defaults to the current sys.stdout.\n", + "flush\n", + " whether to forcibly flush the stream.\n", + "\u001b[1;31mType:\u001b[0m builtin_function_or_method" + ] + } + ], "source": [ "print?" ] @@ -141,9 +197,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 7, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Happy Python programming\n", + "Happy 🐍 Python 🐍 programming\n", + "Happy Python programming 👍\n", + "Happy 🐍 Python 🐍 programming 👍" + ] + } + ], "source": [ "print(\"Happy\", \"Python\", \"programming\")\n", "print(\"Happy\", \"Python\", \"programming\", sep=\" 🐍 \")\n", @@ -176,9 +243,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 1 2 3 4 0\n", + "\n", + "1\n", + "\n", + "2\n", + "\n", + "3\n", + "\n", + "4\n", + "\n" + ] + } + ], "source": [ "for i in range(5):\n", " print(i, end=\" \")\n", @@ -187,6 +271,64 @@ " print(i, end=\"\\n\\n\")" ] }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 1 2 3 4 0\n", + "1\n", + "2\n", + "3\n", + "4\n" + ] + } + ], + "source": [ + "# First loop: Print 0 1 2 3 4 on the same line\n", + "for i in range(5):\n", + " print(i, end=\" \")\n", + "\n", + "# Second loop: Print 0, 1, 2, 3, 4 each on a new line\n", + "for i in range(5):\n", + " print(i) # Default print behavior with a newline after each number\n", + "\n" + ] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "0 1 2 3 4 1\n", + "\n", + "2\n", + "\n", + "3\n", + "\n", + "4\n", + "\n" + ] + } + ], + "source": [ + "# \n", + "for i in range(5):\n", + " print(i, end=\" \")\n", + "\n", + "# start at 1 to avoid printing 1 \n", + "for i in range(1, 5): # start at 1 \n", + " print(i, end=\"\\n\\n\")\n" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -204,10 +346,45 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], - "source": [] + "source": [ + "# def fac function\n", + "def fac(n):\n", + " \n", + " if n == 0 or n == 1:\n", + " return 1\n", + " else:\n", + " result = 1\n", + " for i in range(2, n + 1): #multiply 2 to n\n", + " result *= i\n", + " return result\n" + ] + }, + { + "cell_type": "code", + "execution_count": 6, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The factorial of 4 is: 24\n" + ] + } + ], + "source": [ + "# ask user for int\n", + "n = int(input(\"Enter a non-negative integer: \"))\n", + "\n", + "# call fac function with input \n", + "factorial_result = fac(n)\n", + "\n", + "# print result\n", + "print(f\"The factorial of {n} is: {factorial_result}\")\n" + ] }, { "cell_type": "markdown", @@ -229,10 +406,34 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], - "source": [] + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Your BMI is: 5.56\n" + ] + } + ], + "source": [ + "# define BMI function\n", + "def BMI(weight, height):\n", + " # calculate by weight and height\n", + " bmi = weight / (height ** 2)\n", + " return bmi\n", + "\n", + "# get user input for weight and height\n", + "weight = float(input(\"Enter weight in kilograms (kg): \")) # kilograms\n", + "height = float(input(\"Enter height in meters (m): \")) # height in meters\n", + "\n", + "# call the BMI function print result\n", + "bmi_result = BMI(weight, height)\n", + "\n", + "\n", + "print(f\"Your BMI is: {bmi_result:.2f}\")\n" + ] } ], "metadata": { @@ -254,9 +455,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_5/w5u4.ipynb b/week_5/w5u4.ipynb index 41b1f83..470e2a3 100644 --- a/week_5/w5u4.ipynb +++ b/week_5/w5u4.ipynb @@ -21,9 +21,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Listening to Blitzkrieg Bop\n" + ] + } + ], "source": [ "global_song = \"Blitzkrieg Bop\"\n", "\n", @@ -64,9 +72,21 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'song' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[2], line 5\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mplay_music\u001b[39m():\n\u001b[0;32m 2\u001b[0m song \u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mListening to 100\u001b[39m\u001b[38;5;124m%\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m----> 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(\u001b[43msong\u001b[49m)\n", + "\u001b[1;31mNameError\u001b[0m: name 'song' is not defined" + ] + } + ], "source": [ "def play_music():\n", " song = \"Listening to 100%\"\n", @@ -86,9 +106,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Listening to 100%\n", + "Listening to Blitzkrieg Bop\n", + "Listening to Blue Train\n", + "Twinkle Twinkle Little Star\n" + ] + } + ], "source": [ "song = \"Twinkle Twinkle Little Star\"\n", "\n", @@ -126,9 +157,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Listening to 100%\n", + "Twinkle Twinkle Little Star\n" + ] + } + ], "source": [ "song = \"Twinkle Twinkle Little Star\"\n", "\n", @@ -151,9 +191,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Listening to Blue Train\n", + "Value of the global variable song: Twinkle Twinkle Little Star\n" + ] + } + ], "source": [ "song = \"Twinkle Twinkle Little Star\"\n", "\n", @@ -180,9 +229,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Bad brain\n", + "Bad brain\n" + ] + } + ], "source": [ "song = \"Blitzkrieg Bop\"\n", "\n", @@ -232,9 +290,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_5/w5u5.ipynb b/week_5/w5u5.ipynb index 99981fb..5485c1c 100644 --- a/week_5/w5u5.ipynb +++ b/week_5/w5u5.ipynb @@ -38,7 +38,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -66,9 +66,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The product of the two numbers is 30\n" + ] + } + ], "source": [ "def multiply(a, b):\n", " return a * b\n", @@ -140,9 +148,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10 is a prime: False\n", + "17 is a prime: True\n" + ] + } + ], "source": [ "def is_divisible(a, b):\n", " \"\"\"\n", @@ -186,9 +203,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The possible number of combinations to draw 6 numbers from 49 numbers is 13983816.\n" + ] + } + ], "source": [ "def factorial(n):\n", " result = 1\n", @@ -215,6 +240,41 @@ ")" ] }, + { + "cell_type": "code", + "execution_count": 7, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "10\n" + ] + } + ], + "source": [ + "# my week 3 code\n", + "def fac(n):\n", + " if n == 0 or n == 1:\n", + " return 1\n", + " else:\n", + " result = 1\n", + " for i in range(2, n + 1): # multiply 2 to n\n", + " result *= i\n", + " return result\n", + "\n", + "# function\n", + "def binomial(n, k):\n", + " if k > n:\n", + " return 0 # binomial coefficient is 0 if k > n\n", + " return fac(n) // (fac(k) * fac(n - k))\n", + "\n", + "\n", + "print(binomial(5, 2))\n", + "\n" + ] + }, { "cell_type": "markdown", "metadata": {}, @@ -241,9 +301,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 8, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Listening to Blitzkrieg Bop\n" + ] + } + ], "source": [ "song = \"\"\n", "\n", @@ -269,11 +337,8 @@ } ], "metadata": { - "interpreter": { - "hash": "9fd0e282e2343d8b38b390b803aabc7fcea80a18eee8e5bd23ce64f6435b30a1" - }, "kernelspec": { - "display_name": "Python 3 (ipykernel)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -287,9 +352,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.10" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_5/w5u6.ipynb b/week_5/w5u6.ipynb index 4d0fb4d..08243e8 100644 --- a/week_5/w5u6.ipynb +++ b/week_5/w5u6.ipynb @@ -35,9 +35,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Listening to Blue Train\n" + ] + } + ], "source": [ "song = \"Blue Train\"\n", "\n", @@ -69,9 +77,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Listening to ACE OF SPADES\n" + ] + } + ], "source": [ "song = \"Ace of Spades\"\n", "turned_up_song = song.upper()\n", @@ -97,9 +113,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Listening to Ace of Spaces\n", + "Listening to Blitzkrieg Bop\n", + "Listening to Blue Train\n" + ] + } + ], "source": [ "songs = \"Ace of Spaces, Blitzkrieg Bop, Blue Train\"\n", "song_list = songs.split(\", \")\n", @@ -126,9 +152,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "['ACE OF SPACES', 'BLITZKRIEG BOP', 'BLUE TRAIN']\n" + ] + } + ], "source": [ "songs = \"Ace of Spaces, Blitzkrieg Bop, Blue Train\"\n", "upper_song_list = songs.upper().split(\", \")\n", @@ -158,11 +192,8 @@ } ], "metadata": { - "interpreter": { - "hash": "9fd0e282e2343d8b38b390b803aabc7fcea80a18eee8e5bd23ce64f6435b30a1" - }, "kernelspec": { - "display_name": "Python 3.9.9 64-bit ('opensap_python_intro-SgMpohZV': pipenv)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -176,9 +207,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.1" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_5/w5u7.ipynb b/week_5/w5u7.ipynb index a092afc..3ad659a 100644 --- a/week_5/w5u7.ipynb +++ b/week_5/w5u7.ipynb @@ -15,9 +15,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "('Ace of Spades', 'Dirty', 'Blue Train')\n" + ] + } + ], "source": [ "def my_favorite_songs():\n", " song_1 = \"Ace of Spades\"\n", @@ -43,9 +51,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My favorite song is Ace of Spades\n" + ] + } + ], "source": [ "print(\"My favorite song is\", my_favorite_songs()[0])" ] @@ -60,9 +76,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My favorite song is Ace of Spades\n", + "My 3rd favorite song is Blue Train\n" + ] + } + ], "source": [ "favorite_song, _, least_favorite_song = my_favorite_songs()\n", "\n", @@ -85,9 +110,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "4\n" + ] + } + ], "source": [ "# show content of _ variable\n", "print(_)" @@ -106,9 +139,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My favorite song is Ace of Spades\n", + "The rest of the songs are ['Dirty', 'Blue Train']\n" + ] + } + ], "source": [ "favorite_song, *rest = my_favorite_songs()\n", "\n", @@ -128,9 +170,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 14, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "My least favorite song is Blue Train\n", + "The rest of the songs are ['Ace of Spades', 'Dirty']\n" + ] + } + ], "source": [ "*favorite_songs, least_favorite_song = my_favorite_songs()\n", "\n", @@ -150,9 +201,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The smallest prime number in the list is 2 , the largest 19\n" + ] + } + ], "source": [ "primes = [2, 3, 5, 7, 11, 13, 17, 19]\n", "smallest_prime, *_, largest_prime = primes\n", @@ -177,9 +236,19 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The first element in the range is 0\n", + "The second element is 3\n", + "The rest is [6, 9, 12, 15, 18]\n" + ] + } + ], "source": [ "first_number, second_number, *rest = range(0, 20, 3)\n", "print(\"The first element in the range is\", first_number)\n", @@ -199,9 +268,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 17, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ace of Spades has been played 99 times.\n", + "Blue Train has been played 42 times.\n", + "Dirty has been played 23 times.\n", + "Blitzkrieg Bop has been played 17 times.\n" + ] + } + ], "source": [ "songs = [\n", " (\"Ace of Spades\", 99),\n", @@ -225,9 +305,20 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 18, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Ace of Spades has been played 99 times.\n", + "Blue Train has been played 42 times.\n", + "Dirty has been played 23 times.\n", + "Blitzkrieg Bop has been played 17 times.\n" + ] + } + ], "source": [ "songs = [\n", " (\"Ace of Spades\", 99),\n", @@ -243,11 +334,8 @@ } ], "metadata": { - "interpreter": { - "hash": "9fd0e282e2343d8b38b390b803aabc7fcea80a18eee8e5bd23ce64f6435b30a1" - }, "kernelspec": { - "display_name": "Python 3.9.9 64-bit ('opensap_python_intro-SgMpohZV': pipenv)", + "display_name": "Python 3", "language": "python", "name": "python3" }, @@ -261,9 +349,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.10.1" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_6/w6u2.ipynb b/week_6/w6u2.ipynb index e5791ce..5d13a74 100644 --- a/week_6/w6u2.ipynb +++ b/week_6/w6u2.ipynb @@ -18,7 +18,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -42,9 +42,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The value of cos(π) is -1.0\n", + "The value of sin(π/2) is 1.0\n" + ] + } + ], "source": [ "x = math.cos(math.pi)\n", "print(\"The value of cos(π) is\", x)\n", @@ -63,9 +72,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The value of 0.9999999999999999\n" + ] + } + ], "source": [ "import math as m\n", "\n", @@ -97,9 +114,17 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The value of sin(3 * π /2) is -1.0\n" + ] + } + ], "source": [ "from math import sin, pi\n", "\n", @@ -123,9 +148,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The value of sin(0) is: 0.0\n", + "The value of sin(0) is: I don't know how to calculate the sine of 0\n" + ] + } + ], "source": [ "from math import sin\n", "\n", @@ -154,9 +188,18 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The value of sin(0) is: 0.0\n", + "The value of sin(0) is: 0.0\n" + ] + } + ], "source": [ "import math as m\n", "\n", @@ -210,9 +253,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_6/w6u3.ipynb b/week_6/w6u3.ipynb index f3afda1..4a84288 100644 --- a/week_6/w6u3.ipynb +++ b/week_6/w6u3.ipynb @@ -26,11 +26,52 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "the factorial of 88 is: 185482642257398439114796845645546284380220968949399346684421580986889562184028199319100141244804501828416633516851200000000000000000000\n", + "the natural logarithm of 88 is: 4.477336814478207\n", + "the logarithm base 10 of 88 is: 1.9444826721501687\n" + ] + } + ], "source": [ - "# Implement your solution here" + "# import the math library\n", + "import math\n", + "\n", + "# ask the user for an integer \n", + "user_input = input(\"enter an integer number: \")\n", + "\n", + "try:\n", + " # convert the input to an integer\n", + " number = int(user_input)\n", + "\n", + " # check if the number is non-negative for factorial calculation\n", + " if number < 0:\n", + " print(\"factorial is not defined for negative numbers.\")\n", + " else:\n", + " # calculate the factorial\n", + " factorial = math.factorial(number)\n", + " print(\"the factorial of\", number, \"is:\", factorial)\n", + "\n", + " # check if the number is positive for logarithm calculations\n", + " if number > 0:\n", + " # calculate the natural logarithm\n", + " natural_log = math.log(number)\n", + " print(\"the natural logarithm of\", number, \"is:\", natural_log)\n", + "\n", + " # calculate the logarithm base 10\n", + " log_base_10 = math.log10(number)\n", + " print(\"the logarithm base 10 of\", number, \"is:\", log_base_10)\n", + " else:\n", + " print(\"logarithms are not defined for non-positive numbers.\")\n", + "except ValueError:\n", + " # handle the case where the input is not an integer\n", + " print(\"please enter a valid integer.\")\n" ] }, { @@ -51,11 +92,42 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "list of 100 random numbers: [9, 7, 10, 2, 6, 7, 5, 8, 3, 7, 9, 1, 6, 6, 8, 1, 7, 10, 9, 6, 8, 5, 6, 6, 5, 9, 6, 6, 2, 9, 2, 3, 3, 7, 8, 1, 3, 9, 1, 6, 4, 1, 6, 3, 10, 8, 6, 1, 10, 3, 3, 10, 6, 2, 2, 2, 5, 6, 3, 1, 8, 2, 2, 1, 10, 3, 4, 6, 5, 3, 1, 2, 4, 6, 8, 3, 4, 2, 3, 10, 2, 2, 6, 3, 10, 3, 8, 8, 3, 3, 3, 4, 4, 5, 1, 2, 8, 5, 8, 5]\n", + "mean of the list: 5.04\n", + "median of the list: 5.0\n", + "variance of the list: 7.897373737373737\n" + ] + } + ], "source": [ - "# Implement your solution here" + "# import the random and statistics libraries\n", + "import random\n", + "import statistics\n", + "\n", + "# generate a list of 100 random integers between 1 and 10\n", + "random_numbers = [random.randint(1, 10) for _ in range(100)]\n", + "\n", + "# calculate the mean of the list\n", + "mean_value = statistics.mean(random_numbers)\n", + "\n", + "# calculate the median of the list\n", + "median_value = statistics.median(random_numbers)\n", + "\n", + "# calculate the variance of the list\n", + "variance_value = statistics.variance(random_numbers)\n", + "\n", + "# display the results\n", + "print(\"list of 100 random numbers:\", random_numbers)\n", + "print(\"mean of the list:\", mean_value)\n", + "print(\"median of the list:\", median_value)\n", + "print(\"variance of the list:\", variance_value)\n" ] } ], @@ -78,9 +150,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.1" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +} diff --git a/week_6/w6u6.ipynb b/week_6/w6u6.ipynb index b3fc7d9..dfcf916 100644 --- a/week_6/w6u6.ipynb +++ b/week_6/w6u6.ipynb @@ -21,9 +21,26 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, "metadata": {}, "outputs": [], + "source": [ + "import requests" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The word 'Python' is used 1672 times in its Wikipedia entry!\n" + ] + } + ], "source": [ "import requests\n", "\n", @@ -46,9 +63,136 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, - "outputs": [], + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "US politics liveTrump picks ‘Dr Oz’ to oversee Medicare and Medicaid while working with RFK Jr to ‘take on the illness industrial complex’\n", + "Full storyTrump nominates ‘Dr Oz’ as Medicare and Medicaid services administrator\n", + "PoliticsMarjorie Taylor Greene issues warning to Republicans opposing Gaetz nomination\n", + "Trump administrationTrump picks Howard Lutnick as commerce secretary\n", + "Russia-Ukraine warUS and Europe fear escalation of Russian hybrid warfare amid Ukraine missile attacks\n", + "G20Ukraine allies criticize G20 statement for not naming Russia’s role in conflict\n", + "LiveSpaceX successfully launches giant Starship rocket but won’t catch it with mechanical arms \n", + "SpaceXDonald Trump joins Elon Musk for SpaceX Starship rocket launch\n", + "AlaskaCarcass of giant fin whale draws scores of onlookers to Alaska beach\n", + "EducationTexas education board signals support for Bible-infused school curriculum\n", + "Israel-Gaza warFood prices soar in Gaza after looting of almost 100 aid trucks worsens shortages\n", + "VenezuelaUS recognizes Edmundo González Urrutia as Venezuelan ‘president-elect’\n", + "San FranciscoSan Francisco sees 54% drop in overdose deaths in lowest count since 2020\n", + "New YorkMan charged with murder after three stabbed in New York City rampage\n", + "WildlifeSalmon are ‘coming home’ to spawn in Klamath River after dams are removed\n", + "ColoradoJared Polis, who praised Trump’s pick of RFK Jr, on why he’s willing to work with incoming president\n", + "This is climate breakdownI’m imagining what my mother went through in her last seconds\n", + "MusicThe Mars Volta: ‘The world we were in was very sexist and homophobic’\n", + "ReviewWicked review – Cynthia Erivo and Ariana Grande are a blast in sugar-rush Wizard of Oz fantasy\n", + "All about breasts‘My scars aren’t a finish line’: three trans and non-binary people on how top surgery changed their lives\n", + "Sexual healingMy boyfriend finds menstruation unappealing – and I feel rejected every month\n", + "TV reviewInterior Chinatown review – ambitious, yet tiring, adaptation of Charles Yu’s novel\n", + "FilmPimpinero: Blood and Oil review – road thrills with South American border smugglers\n", + "New YorkA Keith Haring carousel, a Basquiat ferris wheel: long-lost pop art carnival gets new life in New York\n", + "Late-night TV roundupJon Stewart to Democrats: ‘Exploit the loopholes’\n", + "Pass notesJekyll and Hyde managers: why they’re worse than consistently horrible bosses\n", + "To protect US democracy from tyrants, we must protect the truly free press\n", + "Why Kamala Harris couldn’t convince an anti-establishment America\n", + "He has already fathered many children. Now Musk wants all of the US to embrace extreme breeding\n", + "EditorialThe Guardian view on a showtrial in Hong Kong: a new authoritarian low\n", + "Spare a sob for Don Jr – replaced in Daddy’s affections by Elon Musk\n", + "TennisAdios? Nadal beaten at Davis Cup finals in potential farewell \n", + "TennisFederer hails Nadal: ‘You made me reimagine my game’\n", + "VideoNadal says he 'doesn't have ego' to prolong career\n", + "The RecapSign up for our free email of editors' highlights\n", + "NBASixers’ Maxey reportedly calls out Embiid over tardiness amid 2-11 start\n", + "NBACan Lakers ‘sicko’ JJ Redick change the way NBA teams think about coaches?\n", + "NFLJets sack general manager Douglas amid nightmarish season\n", + "Manchester City Guardiola agrees new one-year contract \n", + "USAWeah sparks a goal-fest; Pulisic is Captain Maga: five things we learned from USMNT\n", + "ChelseaBlues denounce abuse aimed at Kerr and Mewis after baby news\n", + "NFLRoof falls in on Cowboys as Houston Texans extend Dallas’s slump\n", + "Cop29China and India should not be called developing countries, several Cop29 delegates say\n", + "Pacific islandsParis agreement is working, Australian minister tells Cop29, but much deeper cuts needed by 2035\n", + "EnvironmentHundreds of lobbyists for industrial farming attend Cop29 climate summit\n", + "Cop29‘It is feasible’: climate finance won’t burden rich countries, say economists\n", + "Donald TrumpProsecutors plan to fight Trump’s push to dismiss hush-money case\n", + "US CongressRepublican bathroom bill targets Congress’s first transgender member \n", + "Los AngelesGavin Newsom delays clemency decision for Lyle and Erik Menéndez\n", + "DetroitSugar plum scaries: Detroit ballet group scrambles after Nutcracker props heist\n", + "MediaMSNBC’s Joe Scarborough brushes off backlash to his meeting with Trump\n", + "Matt GaetzTrump reportedly doubts senators will back Matt Gaetz but still lobbies hard\n", + "Bird fluBird flu in Canada may have mutated to become more transmissible to humans\n", + "US YouTuber Rosanna Pansino smokes cannabis grown from her father’s ashes\n", + "BooksSandra Gilbert, co-author of The Madwoman in the Attic, dies aged 87\n", + "BooksHarperCollins to allow tech firms to use its books to train AI models\n", + "UkraineZelenskyy says North Korea may send 100k troops to Ukraine, as war reaches 1,000 days\n", + "BusinessGlobal stock markets fall and bonds jump as fears grow over Ukraine war\n", + "BusinessGlobal stock markets fall and bonds jump as fears grow over Ukraine war\n", + "Andrew TateRomanian appeal court finds flaws in case against Andrew Tate\n", + "Jimmy LaiHong Kong media mogul Jimmy Lai to take witness stand in collusion trial\n", + "Hong KongInternational outrage over sentencing of 45 pro-democracy activists in Hong Kong\n", + "G20Take two: Biden makes it into G20 leaders’ photo after missing first one\n", + "IrelandConor McGregor accuser ‘will always be a marked woman’, court hears\n", + "HaitiAt least 28 suspected gang members killed in Port-au-Prince, say Haiti police\n", + "El SalvadorEl Salvador ex-president among 11 to face trial for 1989 murder of Jesuits\n", + "BrazilBrazilian police arrest five over plot to assassinate Lula after 2022 election win\n", + "GermanyScholz under pressure to stand aside for Pistorius before German election\n", + "UK ‘We were horrified’: parents heartbroken as baby girl registered as male\n", + "Today in FocusOne man on his grief for Gaza\n", + "The Guardian's Women's Football WeeklyNorth London is red and Merseyside is blue – Women’s Football Weekly\n", + "Comfort Eating with Grace DentS8, Ep9: Monica Dolan, actor\n", + "ScienceWhat does it take to become an astronaut? – podcast\n", + "Today in FocusInside Port-au-Prince, Haiti: the capital where gangs have taken over - podcast\n", + "Politics Weekly UKChina, Ukraine and the assisted dying bill – Politics Weekly Westminster\n", + "Great movies can play fast and loose with history. But not Gladiator II with its rhinos and cafe culture\n", + "MusicTwo Bee Gees drummers die within days of one another\n", + "Stream teamBram Stoker’s Dracula: Francis Ford Coppola’s very horny vampire epic\n", + "ArchitectureCelebrated, reviled, reborn: Paul Rudolph, the brutalist architect with a party streak\n", + "Music‘A road trip like no other’: my epic drive on Kraftwerk’s Autobahn\n", + "Gladiator IIRidley Scott says Denzel Washington’s same-sex kiss in Gladiator II ‘didn’t happen’\n", + "TechScape Betting markets come for everything – and the FBI comes for a betting market\n", + "Kitchen aideWhat’s the best way to cook long-grain rice?\n", + "FoodNigel Slater’s recipe for coffee cream liqueur trifle\n", + "The FilterBlack Friday 2024: how to find a deal and not get ripped off\n", + "Well actuallyWellness influencers love bovine colostrum – but what is it?\n", + "HealthDoes your jaw click? Do you grind your teeth? It could be this little-known condition\n", + "Self careNine activists and therapists on coping with post-election overwhelm\n", + "Guardians of the Gibbons\n", + "DivorceDid you have couples therapy to break up with an ex?\n", + "US non-votersTell us why you abstained in the 2024 presidential election\n", + "HealthcareShare your thoughts on family planning\n", + "Social mediaHave you migrated between social media platforms recently?\n", + "BooksRichard Flanagan wins Baillie Gifford nonfiction prize with ‘astonishing’ Question 7\n", + "Middle East crisis‘Total oppression’: West Bank children being killed at unprecedented rate\n", + "UK artThe 80s: Photographing Britain review – a meandering look at pomp, protest – and pork\n", + "ExplainedActivists, professors, legislators: who are the Hong Kong 47? \n", + "Men‘At my signal, unleash hell!’ What the Gladiator films tell us about 21st-century men\n", + "Trump administration‘This is not his first rodeo’: will federal courts be able to rein in Trump?\n", + "RevealedFar-right militia targets US military over baseless hurricane ‘weather weapon’ claims\n", + "OilWhy Trump’s ‘drill, baby, drill’ pledge may not actually lower US gas prices\n", + "Climate crisis The Guardian environment pledge 2024\n", + "PoliticsWhat are recess appointments and can Trump confirm nominees that way?\n", + "EuropeBarcelona mayor defends ban on tourist flats saying ‘drastic’ action needed to cut housing costs\n", + "Sign up for Fighting Back: a pop-up newsletter on defending democracy under Trump\n", + "Sign up for Well Actually: a free weekly newsletter about health and wellness\n", + "Sign up for Soccer with Jonathan Wilson: his free weekly newsletter\n", + "Sign up for Guardian Headlines US: a daily snapshot of the news straight to your inbox\n", + "\n", + "\t\t\t\tPlay the Guardian's daily word game and share your score with your\n", + "\t\t\t\tfriends\n", + "\t\t\t\n", + "Photos of the dayProtests, floods and a happy hula-hooper: photos of the day\n", + "In picturesNoodles, AI skyscraping and survival: inside Kowloon Walled City\n", + "PhotographyAmerican: Robin de Puy’s portraits of people at a time of division\n", + "NewsA pond cluster and Santa school: photos of the day \n", + "PhotographyThe bee project helping to tackle elephant-human conflict in Kenya\n", + "FashionWe love: fashion fixes for the week ahead – in pictures\n", + "Most viewed\n", + "Deeply read\n" + ] + } + ], "source": [ "import requests\n", "from bs4 import BeautifulSoup\n", @@ -73,7 +217,24 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "import tkinter as tk\n", + "\n", + "# create the main window\n", + "root = tk.Tk()\n", + "root.title(\"Test Tkinter App\")\n", + "root.geometry(\"300x200\") # set the window size\n", + "\n", + "# run the application\n", + "root.mainloop()\n" + ] + }, + { + "cell_type": "code", + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -122,21 +283,6 @@ "With `head(`*`x`*`)` and `tail(`*`x`*`)`, you can return the first/last *x* lines of your data." ] }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [ - "import pandas as pd\n", - "\n", - "dataframe = pd.read_csv(\"gyro_accel.csv\", sep=\";\")\n", - "\n", - "print(dataframe.info())\n", - "\n", - "print(dataframe.head(2))" - ] - }, { "cell_type": "markdown", "metadata": {}, @@ -145,27 +291,62 @@ ] }, { - "cell_type": "code", - "execution_count": null, + "cell_type": "markdown", "metadata": {}, - "outputs": [], "source": [ - "print(dataframe[\"Z_ACCL (32 bit)\"])" + "You could calculate the mean value of your columns iterating through your data yourself, but with `pandas`, this takes\n", + "just one function call:" ] }, { - "cell_type": "markdown", + "cell_type": "code", + "execution_count": 14, "metadata": {}, + "outputs": [ + { + "ename": "FileNotFoundError", + "evalue": "[Errno 2] No such file or directory: 'C:/path/to/your/file/gyro_accel.csv'", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mFileNotFoundError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[14], line 3\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mpandas\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mpd\u001b[39;00m\n\u001b[1;32m----> 3\u001b[0m dataframe \u001b[38;5;241m=\u001b[39m \u001b[43mpd\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mread_csv\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mC:/path/to/your/file/gyro_accel.csv\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43msep\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m;\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28mprint\u001b[39m(dataframe\u001b[38;5;241m.\u001b[39minfo())\n\u001b[0;32m 7\u001b[0m \u001b[38;5;28mprint\u001b[39m(dataframe\u001b[38;5;241m.\u001b[39mhead(\u001b[38;5;241m2\u001b[39m))\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\pandas\\io\\parsers\\readers.py:1026\u001b[0m, in \u001b[0;36mread_csv\u001b[1;34m(filepath_or_buffer, sep, delimiter, header, names, index_col, usecols, dtype, engine, converters, true_values, false_values, skipinitialspace, skiprows, skipfooter, nrows, na_values, keep_default_na, na_filter, verbose, skip_blank_lines, parse_dates, infer_datetime_format, keep_date_col, date_parser, date_format, dayfirst, cache_dates, iterator, chunksize, compression, thousands, decimal, lineterminator, quotechar, quoting, doublequote, escapechar, comment, encoding, encoding_errors, dialect, on_bad_lines, delim_whitespace, low_memory, memory_map, float_precision, storage_options, dtype_backend)\u001b[0m\n\u001b[0;32m 1013\u001b[0m kwds_defaults \u001b[38;5;241m=\u001b[39m _refine_defaults_read(\n\u001b[0;32m 1014\u001b[0m dialect,\n\u001b[0;32m 1015\u001b[0m delimiter,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 1022\u001b[0m dtype_backend\u001b[38;5;241m=\u001b[39mdtype_backend,\n\u001b[0;32m 1023\u001b[0m )\n\u001b[0;32m 1024\u001b[0m kwds\u001b[38;5;241m.\u001b[39mupdate(kwds_defaults)\n\u001b[1;32m-> 1026\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_read\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilepath_or_buffer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mkwds\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\pandas\\io\\parsers\\readers.py:620\u001b[0m, in \u001b[0;36m_read\u001b[1;34m(filepath_or_buffer, kwds)\u001b[0m\n\u001b[0;32m 617\u001b[0m _validate_names(kwds\u001b[38;5;241m.\u001b[39mget(\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mnames\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;28;01mNone\u001b[39;00m))\n\u001b[0;32m 619\u001b[0m \u001b[38;5;66;03m# Create the parser.\u001b[39;00m\n\u001b[1;32m--> 620\u001b[0m parser \u001b[38;5;241m=\u001b[39m \u001b[43mTextFileReader\u001b[49m\u001b[43m(\u001b[49m\u001b[43mfilepath_or_buffer\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[38;5;241;43m*\u001b[39;49m\u001b[43mkwds\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 622\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m chunksize \u001b[38;5;129;01mor\u001b[39;00m iterator:\n\u001b[0;32m 623\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m parser\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\pandas\\io\\parsers\\readers.py:1620\u001b[0m, in \u001b[0;36mTextFileReader.__init__\u001b[1;34m(self, f, engine, **kwds)\u001b[0m\n\u001b[0;32m 1617\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39moptions[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhas_index_names\u001b[39m\u001b[38;5;124m\"\u001b[39m] \u001b[38;5;241m=\u001b[39m kwds[\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhas_index_names\u001b[39m\u001b[38;5;124m\"\u001b[39m]\n\u001b[0;32m 1619\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles: IOHandles \u001b[38;5;241m|\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[1;32m-> 1620\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39m_engine \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_make_engine\u001b[49m\u001b[43m(\u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mengine\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\pandas\\io\\parsers\\readers.py:1880\u001b[0m, in \u001b[0;36mTextFileReader._make_engine\u001b[1;34m(self, f, engine)\u001b[0m\n\u001b[0;32m 1878\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m mode:\n\u001b[0;32m 1879\u001b[0m mode \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[1;32m-> 1880\u001b[0m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles \u001b[38;5;241m=\u001b[39m \u001b[43mget_handle\u001b[49m\u001b[43m(\u001b[49m\n\u001b[0;32m 1881\u001b[0m \u001b[43m \u001b[49m\u001b[43mf\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1882\u001b[0m \u001b[43m \u001b[49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1883\u001b[0m \u001b[43m \u001b[49m\u001b[43mencoding\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mencoding\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1884\u001b[0m \u001b[43m \u001b[49m\u001b[43mcompression\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mcompression\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1885\u001b[0m \u001b[43m \u001b[49m\u001b[43mmemory_map\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mmemory_map\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mFalse\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1886\u001b[0m \u001b[43m \u001b[49m\u001b[43mis_text\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mis_text\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1887\u001b[0m \u001b[43m \u001b[49m\u001b[43merrors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mencoding_errors\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mstrict\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1888\u001b[0m \u001b[43m \u001b[49m\u001b[43mstorage_options\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43moptions\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mget\u001b[49m\u001b[43m(\u001b[49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43mstorage_options\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[38;5;28;43;01mNone\u001b[39;49;00m\u001b[43m)\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 1889\u001b[0m \u001b[43m\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 1890\u001b[0m \u001b[38;5;28;01massert\u001b[39;00m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles \u001b[38;5;129;01mis\u001b[39;00m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;28;01mNone\u001b[39;00m\n\u001b[0;32m 1891\u001b[0m f \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mhandles\u001b[38;5;241m.\u001b[39mhandle\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\pandas\\io\\common.py:873\u001b[0m, in \u001b[0;36mget_handle\u001b[1;34m(path_or_buf, mode, encoding, compression, memory_map, is_text, errors, storage_options)\u001b[0m\n\u001b[0;32m 868\u001b[0m \u001b[38;5;28;01melif\u001b[39;00m \u001b[38;5;28misinstance\u001b[39m(handle, \u001b[38;5;28mstr\u001b[39m):\n\u001b[0;32m 869\u001b[0m \u001b[38;5;66;03m# Check whether the filename is to be opened in binary mode.\u001b[39;00m\n\u001b[0;32m 870\u001b[0m \u001b[38;5;66;03m# Binary mode does not support 'encoding' and 'newline'.\u001b[39;00m\n\u001b[0;32m 871\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m ioargs\u001b[38;5;241m.\u001b[39mencoding \u001b[38;5;129;01mand\u001b[39;00m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mb\u001b[39m\u001b[38;5;124m\"\u001b[39m \u001b[38;5;129;01mnot\u001b[39;00m \u001b[38;5;129;01min\u001b[39;00m ioargs\u001b[38;5;241m.\u001b[39mmode:\n\u001b[0;32m 872\u001b[0m \u001b[38;5;66;03m# Encoding\u001b[39;00m\n\u001b[1;32m--> 873\u001b[0m handle \u001b[38;5;241m=\u001b[39m \u001b[38;5;28;43mopen\u001b[39;49m\u001b[43m(\u001b[49m\n\u001b[0;32m 874\u001b[0m \u001b[43m \u001b[49m\u001b[43mhandle\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 875\u001b[0m \u001b[43m \u001b[49m\u001b[43mioargs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmode\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 876\u001b[0m \u001b[43m \u001b[49m\u001b[43mencoding\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43mioargs\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mencoding\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 877\u001b[0m \u001b[43m \u001b[49m\u001b[43merrors\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[43merrors\u001b[49m\u001b[43m,\u001b[49m\n\u001b[0;32m 878\u001b[0m \u001b[43m \u001b[49m\u001b[43mnewline\u001b[49m\u001b[38;5;241;43m=\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[38;5;124;43m\"\u001b[39;49m\u001b[43m,\u001b[49m\n\u001b[0;32m 879\u001b[0m \u001b[43m \u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 880\u001b[0m \u001b[38;5;28;01melse\u001b[39;00m:\n\u001b[0;32m 881\u001b[0m \u001b[38;5;66;03m# Binary mode\u001b[39;00m\n\u001b[0;32m 882\u001b[0m handle \u001b[38;5;241m=\u001b[39m \u001b[38;5;28mopen\u001b[39m(handle, ioargs\u001b[38;5;241m.\u001b[39mmode)\n", + "\u001b[1;31mFileNotFoundError\u001b[0m: [Errno 2] No such file or directory: 'C:/path/to/your/file/gyro_accel.csv'" + ] + } + ], "source": [ - "You could calculate the mean value of your columns iterating through your data yourself, but with `pandas`, this takes\n", - "just one function call:" + "import pandas as pd\n", + "\n", + "dataframe = pd.read_csv(\"C:/path/to/your/file/gyro_accel.csv\", sep=\";\")\n", + "\n", + "print(dataframe.info())\n", + "\n", + "print(dataframe.head(2))" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "NameError", + "evalue": "name 'dataframe' is not defined", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mNameError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[13], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m mean_values \u001b[38;5;241m=\u001b[39m \u001b[43mdataframe\u001b[49m\u001b[38;5;241m.\u001b[39mmean()\n\u001b[0;32m 2\u001b[0m \u001b[38;5;28mprint\u001b[39m(mean_values)\n", + "\u001b[1;31mNameError\u001b[0m: name 'dataframe' is not defined" + ] + } + ], "source": [ "mean_values = dataframe.mean()\n", "print(mean_values)" @@ -184,9 +365,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ImportError", + "evalue": "DLL load failed while importing _cext: The specified module could not be found.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[15], line 1\u001b[0m\n\u001b[1;32m----> 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mmatplotlib\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mpyplot\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mplt\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;66;03m# set plot size for good visibility\u001b[39;00m\n\u001b[0;32m 4\u001b[0m plt\u001b[38;5;241m.\u001b[39mfigure(figsize\u001b[38;5;241m=\u001b[39m(\u001b[38;5;241m12\u001b[39m, \u001b[38;5;241m6\u001b[39m))\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\matplotlib\\__init__.py:263\u001b[0m\n\u001b[0;32m 258\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m parse_version(module\u001b[38;5;241m.\u001b[39m__version__) \u001b[38;5;241m<\u001b[39m parse_version(minver):\n\u001b[0;32m 259\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMatplotlib requires \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmodname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mminver\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m; \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 260\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myou have \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmodule\u001b[38;5;241m.\u001b[39m__version__\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m--> 263\u001b[0m \u001b[43m_check_versions\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 266\u001b[0m \u001b[38;5;66;03m# The decorator ensures this always returns the same handler (and it is only\u001b[39;00m\n\u001b[0;32m 267\u001b[0m \u001b[38;5;66;03m# attached once).\u001b[39;00m\n\u001b[0;32m 268\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mcache\n\u001b[0;32m 269\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_ensure_handler\u001b[39m():\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\matplotlib\\__init__.py:257\u001b[0m, in \u001b[0;36m_check_versions\u001b[1;34m()\u001b[0m\n\u001b[0;32m 248\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ft2font \u001b[38;5;66;03m# noqa: F401\u001b[39;00m\n\u001b[0;32m 250\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m modname, minver \u001b[38;5;129;01min\u001b[39;00m [\n\u001b[0;32m 251\u001b[0m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcycler\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m0.10\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[0;32m 252\u001b[0m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdateutil\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m2.7\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 255\u001b[0m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpyparsing\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m2.3.1\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[0;32m 256\u001b[0m ]:\n\u001b[1;32m--> 257\u001b[0m module \u001b[38;5;241m=\u001b[39m \u001b[43mimportlib\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mimport_module\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodname\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 258\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m parse_version(module\u001b[38;5;241m.\u001b[39m__version__) \u001b[38;5;241m<\u001b[39m parse_version(minver):\n\u001b[0;32m 259\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMatplotlib requires \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmodname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mminver\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m; \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 260\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myou have \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmodule\u001b[38;5;241m.\u001b[39m__version__\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\importlib\\__init__.py:88\u001b[0m, in \u001b[0;36mimport_module\u001b[1;34m(name, package)\u001b[0m\n\u001b[0;32m 86\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m 87\u001b[0m level \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[1;32m---> 88\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_bootstrap\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_gcd_import\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m[\u001b[49m\u001b[43mlevel\u001b[49m\u001b[43m:\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpackage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlevel\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\kiwisolver\\__init__.py:8\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# --------------------------------------------------------------------------------------\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# Copyright (c) 2013-2024, Nucleic Development Team.\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[38;5;66;03m# The full license is in the file LICENSE, distributed with this software.\u001b[39;00m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;66;03m# --------------------------------------------------------------------------------------\u001b[39;00m\n\u001b[1;32m----> 8\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_cext\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m 9\u001b[0m Constraint,\n\u001b[0;32m 10\u001b[0m Expression,\n\u001b[0;32m 11\u001b[0m Solver,\n\u001b[0;32m 12\u001b[0m Term,\n\u001b[0;32m 13\u001b[0m Variable,\n\u001b[0;32m 14\u001b[0m __kiwi_version__,\n\u001b[0;32m 15\u001b[0m __version__,\n\u001b[0;32m 16\u001b[0m strength,\n\u001b[0;32m 17\u001b[0m )\n\u001b[0;32m 18\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mexceptions\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m 19\u001b[0m BadRequiredStrength,\n\u001b[0;32m 20\u001b[0m DuplicateConstraint,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 24\u001b[0m UnsatisfiableConstraint,\n\u001b[0;32m 25\u001b[0m )\n\u001b[0;32m 27\u001b[0m __all__ \u001b[38;5;241m=\u001b[39m [\n\u001b[0;32m 28\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mBadRequiredStrength\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 29\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuplicateConstraint\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 41\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m__kiwi_version__\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 42\u001b[0m ]\n", + "\u001b[1;31mImportError\u001b[0m: DLL load failed while importing _cext: The specified module could not be found." + ] + } + ], "source": [ "import matplotlib.pyplot as plt\n", "\n", @@ -210,9 +407,25 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, - "outputs": [], + "outputs": [ + { + "ename": "ImportError", + "evalue": "DLL load failed while importing _cext: The specified module could not be found.", + "output_type": "error", + "traceback": [ + "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[1;31mImportError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[1;32mIn[16], line 2\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mrandom\u001b[39;00m\n\u001b[1;32m----> 2\u001b[0m \u001b[38;5;28;01mimport\u001b[39;00m \u001b[38;5;21;01mmatplotlib\u001b[39;00m\u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mpyplot\u001b[39;00m \u001b[38;5;28;01mas\u001b[39;00m \u001b[38;5;21;01mplt\u001b[39;00m\n\u001b[0;32m 4\u001b[0m random_values \u001b[38;5;241m=\u001b[39m []\n\u001b[0;32m 5\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m _ \u001b[38;5;129;01min\u001b[39;00m \u001b[38;5;28mrange\u001b[39m(\u001b[38;5;241m100000\u001b[39m):\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\matplotlib\\__init__.py:263\u001b[0m\n\u001b[0;32m 258\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m parse_version(module\u001b[38;5;241m.\u001b[39m__version__) \u001b[38;5;241m<\u001b[39m parse_version(minver):\n\u001b[0;32m 259\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMatplotlib requires \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmodname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mminver\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m; \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 260\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myou have \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmodule\u001b[38;5;241m.\u001b[39m__version__\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n\u001b[1;32m--> 263\u001b[0m \u001b[43m_check_versions\u001b[49m\u001b[43m(\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 266\u001b[0m \u001b[38;5;66;03m# The decorator ensures this always returns the same handler (and it is only\u001b[39;00m\n\u001b[0;32m 267\u001b[0m \u001b[38;5;66;03m# attached once).\u001b[39;00m\n\u001b[0;32m 268\u001b[0m \u001b[38;5;129m@functools\u001b[39m\u001b[38;5;241m.\u001b[39mcache\n\u001b[0;32m 269\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21m_ensure_handler\u001b[39m():\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\matplotlib\\__init__.py:257\u001b[0m, in \u001b[0;36m_check_versions\u001b[1;34m()\u001b[0m\n\u001b[0;32m 248\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m ft2font \u001b[38;5;66;03m# noqa: F401\u001b[39;00m\n\u001b[0;32m 250\u001b[0m \u001b[38;5;28;01mfor\u001b[39;00m modname, minver \u001b[38;5;129;01min\u001b[39;00m [\n\u001b[0;32m 251\u001b[0m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mcycler\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m0.10\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[0;32m 252\u001b[0m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mdateutil\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m2.7\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 255\u001b[0m (\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mpyparsing\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m2.3.1\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[0;32m 256\u001b[0m ]:\n\u001b[1;32m--> 257\u001b[0m module \u001b[38;5;241m=\u001b[39m \u001b[43mimportlib\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mimport_module\u001b[49m\u001b[43m(\u001b[49m\u001b[43mmodname\u001b[49m\u001b[43m)\u001b[49m\n\u001b[0;32m 258\u001b[0m \u001b[38;5;28;01mif\u001b[39;00m parse_version(module\u001b[38;5;241m.\u001b[39m__version__) \u001b[38;5;241m<\u001b[39m parse_version(minver):\n\u001b[0;32m 259\u001b[0m \u001b[38;5;28;01mraise\u001b[39;00m \u001b[38;5;167;01mImportError\u001b[39;00m(\u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mMatplotlib requires \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmodname\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m>=\u001b[39m\u001b[38;5;132;01m{\u001b[39;00mminver\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m; \u001b[39m\u001b[38;5;124m\"\u001b[39m\n\u001b[0;32m 260\u001b[0m \u001b[38;5;124mf\u001b[39m\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124myou have \u001b[39m\u001b[38;5;132;01m{\u001b[39;00mmodule\u001b[38;5;241m.\u001b[39m__version__\u001b[38;5;132;01m}\u001b[39;00m\u001b[38;5;124m\"\u001b[39m)\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\importlib\\__init__.py:88\u001b[0m, in \u001b[0;36mimport_module\u001b[1;34m(name, package)\u001b[0m\n\u001b[0;32m 86\u001b[0m \u001b[38;5;28;01mbreak\u001b[39;00m\n\u001b[0;32m 87\u001b[0m level \u001b[38;5;241m+\u001b[39m\u001b[38;5;241m=\u001b[39m \u001b[38;5;241m1\u001b[39m\n\u001b[1;32m---> 88\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m \u001b[43m_bootstrap\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43m_gcd_import\u001b[49m\u001b[43m(\u001b[49m\u001b[43mname\u001b[49m\u001b[43m[\u001b[49m\u001b[43mlevel\u001b[49m\u001b[43m:\u001b[49m\u001b[43m]\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mpackage\u001b[49m\u001b[43m,\u001b[49m\u001b[43m \u001b[49m\u001b[43mlevel\u001b[49m\u001b[43m)\u001b[49m\n", + "File \u001b[1;32mc:\\Users\\amand\\AppData\\Local\\Programs\\Python\\Python313\\Lib\\site-packages\\kiwisolver\\__init__.py:8\u001b[0m\n\u001b[0;32m 1\u001b[0m \u001b[38;5;66;03m# --------------------------------------------------------------------------------------\u001b[39;00m\n\u001b[0;32m 2\u001b[0m \u001b[38;5;66;03m# Copyright (c) 2013-2024, Nucleic Development Team.\u001b[39;00m\n\u001b[0;32m 3\u001b[0m \u001b[38;5;66;03m#\u001b[39;00m\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 6\u001b[0m \u001b[38;5;66;03m# The full license is in the file LICENSE, distributed with this software.\u001b[39;00m\n\u001b[0;32m 7\u001b[0m \u001b[38;5;66;03m# --------------------------------------------------------------------------------------\u001b[39;00m\n\u001b[1;32m----> 8\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01m_cext\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m 9\u001b[0m Constraint,\n\u001b[0;32m 10\u001b[0m Expression,\n\u001b[0;32m 11\u001b[0m Solver,\n\u001b[0;32m 12\u001b[0m Term,\n\u001b[0;32m 13\u001b[0m Variable,\n\u001b[0;32m 14\u001b[0m __kiwi_version__,\n\u001b[0;32m 15\u001b[0m __version__,\n\u001b[0;32m 16\u001b[0m strength,\n\u001b[0;32m 17\u001b[0m )\n\u001b[0;32m 18\u001b[0m \u001b[38;5;28;01mfrom\u001b[39;00m \u001b[38;5;21;01m.\u001b[39;00m\u001b[38;5;21;01mexceptions\u001b[39;00m \u001b[38;5;28;01mimport\u001b[39;00m (\n\u001b[0;32m 19\u001b[0m BadRequiredStrength,\n\u001b[0;32m 20\u001b[0m DuplicateConstraint,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 24\u001b[0m UnsatisfiableConstraint,\n\u001b[0;32m 25\u001b[0m )\n\u001b[0;32m 27\u001b[0m __all__ \u001b[38;5;241m=\u001b[39m [\n\u001b[0;32m 28\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mBadRequiredStrength\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 29\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mDuplicateConstraint\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[1;32m (...)\u001b[0m\n\u001b[0;32m 41\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124m__kiwi_version__\u001b[39m\u001b[38;5;124m\"\u001b[39m,\n\u001b[0;32m 42\u001b[0m ]\n", + "\u001b[1;31mImportError\u001b[0m: DLL load failed while importing _cext: The specified module could not be found." + ] + } + ], "source": [ "import random\n", "import matplotlib.pyplot as plt\n", @@ -255,9 +468,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.7.7" + "version": "3.13.0" } }, "nbformat": 4, "nbformat_minor": 2 -} \ No newline at end of file +}