{
  "cells": [
    {
      "cell_type": "markdown",
      "id": "14788333",
      "metadata": {
        "id": "14788333"
      },
      "source": [
        "# Python Fundamentals — 10 Practice Exercises\n",
        "**Computer Practicum · WIS – LES · P04: Introduction to Python**\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "36c217fb",
      "metadata": {
        "id": "36c217fb"
      },
      "source": [
        "---\n",
        "## Exercise 1 — Your first sensor reading\n",
        "\n",
        "A temperature sensor reports **23.4 °C**.\n",
        "\n",
        "1. Store the sensor's name, the measured value, and the unit in variables.\n",
        "2. Print a readable message containing all three, such as `Temperature: 23.4 C`.\n",
        "3. Print the data type of the measured value using `type()`.\n",
        "4. **Colab practice:** Insert a *text cell* below your solution and write one sentence describing what this measurement represents."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "e8b6286c",
      "metadata": {
        "id": "e8b6286c"
      },
      "outputs": [],
      "source": [
        "# Starting values (you may modify them)\n",
        "sensor_name = \"Temperature\"\n",
        "measurement = 23.4\n",
        "unit = \"C\"\n",
        "\n",
        "# Your solution:\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "484563ab",
      "metadata": {
        "id": "484563ab"
      },
      "source": [
        "---\n",
        "## Exercise 2 — Temperature change\n",
        "\n",
        "During a heating experiment, a sensor reads **20.5 °C** at the start and **27.0 °C** at the end.\n",
        "\n",
        "1. Store the initial and final temperatures in separate variables.\n",
        "2. Calculate how much the temperature increased.\n",
        "3. Print the increase, including its unit.\n",
        "\n",
        "**Check:** The increase should be **6.5 °C**."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "a48b51e9",
      "metadata": {
        "id": "a48b51e9"
      },
      "outputs": [],
      "source": [
        "initial_temperature = 20.5\n",
        "final_temperature = 27.0\n",
        "\n",
        "# Your solution:\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "055a2de3",
      "metadata": {
        "id": "055a2de3"
      },
      "source": [
        "---\n",
        "## Exercise 3 — Average temperature\n",
        "\n",
        "Four measurements are taken: **19.8 °C, 20.2 °C, 20.7 °C, and 21.3 °C**.\n",
        "\n",
        "1. Store each reading in a different variable.\n",
        "2. Calculate their arithmetic mean using a single mathematical expression.\n",
        "3. Print the result.\n",
        "\n",
        "**Hint:** Use parentheses to make sure the *sum* is divided by four.\n",
        "\n",
        "**Check:** The mean is **20.5 °C**."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "894914e2",
      "metadata": {
        "id": "894914e2"
      },
      "outputs": [],
      "source": [
        "reading_1 = 19.8\n",
        "reading_2 = 20.2\n",
        "reading_3 = 20.7\n",
        "reading_4 = 21.3\n",
        "\n",
        "# Your solution:\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "5a8901b8",
      "metadata": {
        "id": "5a8901b8"
      },
      "source": [
        "---\n",
        "## Exercise 4 — How long does a measurement session last?\n",
        "\n",
        "A microcontroller takes **11 measurements**, separated by **500 milliseconds**. The first measurement is taken at time zero.\n",
        "\n",
        "1. Store the number of measurements and the interval in variables.\n",
        "2. Calculate the time between the **first and last** measurement, in milliseconds.\n",
        "3. Convert that duration to seconds and print both values.\n",
        "\n",
        "**Hint:** There are 10 intervals between 11 consecutive measurements. **1 second = 1000 milliseconds.**"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "8a08bd4a",
      "metadata": {
        "id": "8a08bd4a"
      },
      "outputs": [],
      "source": [
        "number_of_measurements = 11\n",
        "interval_ms = 500\n",
        "\n",
        "# Your solution:\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "69d52f9f",
      "metadata": {
        "id": "69d52f9f"
      },
      "source": [
        "---\n",
        "## Exercise 5 — A number stored as text\n",
        "\n",
        "A sensor reading was imported as the string `\"42.5\"` rather than as a number.\n",
        "\n",
        "1. Print the original value and its data type.\n",
        "2. Convert it into a floating-point number using `float()`.\n",
        "3. Add **2.0** to the numeric value.\n",
        "4. Print the new value and its data type.\n",
        "\n",
        "**Remember:** A number inside quotation marks is a string."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "37c53954",
      "metadata": {
        "id": "37c53954"
      },
      "outputs": [],
      "source": [
        "measurement_text = \"42.5\"\n",
        "\n",
        "# Your solution:\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "81e0c3ca",
      "metadata": {
        "id": "81e0c3ca"
      },
      "source": [
        "---\n",
        "## Exercise 6 — Make a readable measurement message\n",
        "\n",
        "You want to display a humidity measurement as a single text message.\n",
        "\n",
        "1. Use the variables provided below.\n",
        "2. Build a message by joining strings with the `+` operator.\n",
        "3. Convert the numeric measurement using `str()` where necessary.\n",
        "4. Print this exact message:\n",
        "\n",
        "`Relative humidity: 58.0 %`\n",
        "\n",
        "**Hint:** Combining strings with `+` is different from adding numbers."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "9345a450",
      "metadata": {
        "id": "9345a450"
      },
      "outputs": [],
      "source": [
        "measurement_name = \"Relative humidity\"\n",
        "humidity = 58.0\n",
        "unit = \"%\"\n",
        "\n",
        "# Your solution:\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "320215ee",
      "metadata": {
        "id": "320215ee"
      },
      "source": [
        "---\n",
        "## Exercise 7 — Predict, run, and explain\n",
        "\n",
        "Consider the code cell below.\n",
        "\n",
        "1. **Before running it**, predict the output of both `print()` statements.\n",
        "2. Run the cell and compare the result with your prediction.\n",
        "3. Explain (in a text cell or as a `#` comment) **why the results are different**.\n",
        "4. Modify **only the first `print()` statement** so that both statements produce the same *numeric* result.\n",
        "\n",
        "**Hint:** The `+` operator behaves differently when working with strings and numbers."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "3f675797",
      "metadata": {
        "id": "3f675797"
      },
      "outputs": [],
      "source": [
        "count_text = \"12\"\n",
        "extra_count = 3\n",
        "\n",
        "print(count_text + str(extra_count))\n",
        "print(int(count_text) + extra_count)\n",
        "\n",
        "# Explain the difference, then modify the first print statement.\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "ae024ccb",
      "metadata": {
        "id": "ae024ccb"
      },
      "source": [
        "---\n",
        "## Exercise 8 — Check a measurement against a threshold\n",
        "\n",
        "A temperature sensor reports **24 °C**, and the warning threshold is **25 °C**.\n",
        "\n",
        "1. Store the temperature and threshold in variables.\n",
        "2. Print whether the temperature is **less than** the threshold.\n",
        "3. Print whether it is **equal to** the threshold.\n",
        "4. Print whether it is **greater than or equal to** the threshold.\n",
        "5. Change the temperature to **25 °C** and run the cell again. What changes?\n",
        "\n",
        "**Remember:** `=` assigns a value; `==` tests equality. Print the Boolean expressions directly — `if` statements are not required."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "56540d74",
      "metadata": {
        "id": "56540d74"
      },
      "outputs": [],
      "source": [
        "temperature = 24\n",
        "warning_threshold = 25\n",
        "\n",
        "# Your solution:\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "1145eae7",
      "metadata": {
        "id": "1145eae7"
      },
      "source": [
        "---\n",
        "## Exercise 9 — Detect an out-of-range measurement\n",
        "\n",
        "A humidity sensor measures **82%**. For this exercise, the acceptable range is **30% to 70% (inclusive)**.\n",
        "\n",
        "1. Store the measured humidity in a variable.\n",
        "2. Write **one Boolean expression** that is `True` when the humidity is **below 30% OR above 70%**.\n",
        "3. Print the Boolean result.\n",
        "4. Change the measurement to **50%** and verify that the result changes.\n",
        "\n",
        "**Hint:** Use the logical operator `or`. You do not need an `if` statement."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "09faaa75",
      "metadata": {
        "id": "09faaa75"
      },
      "outputs": [],
      "source": [
        "humidity = 82\n",
        "minimum_humidity = 30\n",
        "maximum_humidity = 70\n",
        "\n",
        "# Your solution:\n"
      ]
    },
    {
      "cell_type": "markdown",
      "id": "969472b7",
      "metadata": {
        "id": "969472b7"
      },
      "source": [
        "---\n",
        "## Exercise 10 — Are the experimental conditions valid?\n",
        "\n",
        "For a particular experiment, the measurements are considered valid only when **all** these requirements hold:\n",
        "\n",
        "- The sensor is connected.\n",
        "- Temperature is between **20 °C and 28 °C**, inclusive.\n",
        "- Humidity is between **30% and 60%**, inclusive.\n",
        "\n",
        "The sensor currently reports a temperature of **24 °C**, humidity of **55%**, and a successful connection.\n",
        "\n",
        "1. Store these values in variables (use `True` or `False` for the connection status).\n",
        "2. Write one Boolean expression combining **all three requirements** with `and` and store its result in a variable named `valid`.\n",
        "3. Print `valid`.\n",
        "4. Use `not` to print whether the experimental conditions are **invalid**.\n",
        "5. Change `sensor_connected` to `False` and test again.\n",
        "\n",
        "**Hint:** You can combine two comparisons for an inclusive range using `>=` and `<=`, then connect conditions with `and`. No `if` statement is required."
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "id": "cb84924c",
      "metadata": {
        "id": "cb84924c"
      },
      "outputs": [],
      "source": [
        "temperature = 24\n",
        "humidity = 55\n",
        "sensor_connected = True\n",
        "\n",
        "# Your solution:\n"
      ]
    }
  ],
  "metadata": {
    "colab": {
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 5
}