{
  "nbformat": 4,
  "nbformat_minor": 5,
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "# ZHUDDLE | Chapter 02: Variables, expressions, and statements\n\n8 coding missions + 10 MCQs. 100 XP.\n\nAdapted from Charles R. Severance, Python for Everybody (CC BY 4.0).\n\nSource: https://www.py4e.com/html3/02-variables\n\nReading: https://www.py4e.com/html3/02-variables\n\nThe browser runs five independent cases per coding mission. This notebook supplies the first sample; input prompts here are interactive.",
      "id": "variables-000"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## C01 | Values and their types\n\nAssign `whole`, `fraction`, and `text` the values 17, 3.2, and the string \"17\". Use `type()` to store their types in `whole_type`, `fraction_type`, and `text_type`.\n\nFive independent checks are worth 2 XP each. \n\n**Source checkpoint:** Values and types",
      "id": "variables-001"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "whole = None\nfraction = None\ntext = None\nwhole_type = None\nfraction_type = None\ntext_type = None",
      "execution_count": null,
      "outputs": [],
      "id": "variables-002"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## C02 | Assignment and updates\n\nThe checker supplies `n`. Store its value in `original`, increase `n` by 1, and print the updated number.\n\nFive independent checks are worth 2 XP each. The checker supplies the variables below with different values on each check. Use them without replacing their starting values.\n\n```python\nn = 17\n```\n\n**Source checkpoint:** Variables; Statements",
      "id": "variables-003"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "n = 17",
      "execution_count": null,
      "outputs": [],
      "id": "variables-004"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "original = None\n# Update n, then print it.",
      "execution_count": null,
      "outputs": [],
      "id": "variables-005"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## C03 | Arithmetic toolbox\n\nUsing supplied integers `a` and `b` (b is positive), calculate `total` (sum), `difference` (a minus b), `product`, `quotient` (true division), and `remainder` (a modulo b).\n\nFive independent checks are worth 2 XP each. The checker supplies the variables below with different values on each check. Use them without replacing their starting values.\n\n```python\na = 7\nb = 3\n```\n\n**Source checkpoint:** Operators and operands; Modulus operator",
      "id": "variables-006"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "a = 7\nb = 3",
      "execution_count": null,
      "outputs": [],
      "id": "variables-007"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "total = None\ndifference = None\nproduct = None\nquotient = None\nremainder = None",
      "execution_count": null,
      "outputs": [],
      "id": "variables-008"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## C04 | Precedence workshop\n\nUse `width` and `height` to compute `floor_half = width // 2`, `decimal_half = width / 2.0`, and `third = height / 3`. Also calculate `expression` from `1 + 2 * 5` and `grouped` from `(1 + 2) * 5`.\n\nFive independent checks are worth 2 XP each. The checker supplies the variables below with different values on each check. Use them without replacing their starting values.\n\n```python\nwidth = 17\nheight = 12.0\n```\n\n**Source checkpoint:** Order of operations; Exercise 4",
      "id": "variables-009"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "width = 17\nheight = 12.0",
      "execution_count": null,
      "outputs": [],
      "id": "variables-010"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "floor_half = None\ndecimal_half = None\nthird = None\nexpression = None\ngrouped = None",
      "execution_count": null,
      "outputs": [],
      "id": "variables-011"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## C05 | Joining and repeating text\n\nJoin `first` and `second` with `+`, saving `joined`. Repeat `first` by the supplied integer `times`, saving `repeated`.\n\nFive independent checks are worth 2 XP each. The checker supplies the variables below with different values on each check. Use them without replacing their starting values.\n\n```python\nfirst = '100'\nsecond = '150'\ntimes = 3\n```\n\n**Source checkpoint:** String operations",
      "id": "variables-012"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "first = '100'\nsecond = '150'\ntimes = 3",
      "execution_count": null,
      "outputs": [],
      "id": "variables-013"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "joined = None\nrepeated = None",
      "execution_count": null,
      "outputs": [],
      "id": "variables-014"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## C06 | A personal welcome\n\nRead one name with `input()` into `name`. Print `Hello` followed by a space and that name.\n\nFive independent checks are worth 2 XP each. \n\nUse `input()` normally: the checker enters test values for you. Sample inputs, in order: `Chuck`. Input prompts are omitted from captured output.\n\n**Source checkpoint:** Asking the user for input; Exercise 2",
      "id": "variables-015"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "# Read a name and welcome the user.",
      "execution_count": null,
      "outputs": [],
      "id": "variables-016"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## C07 | Gross pay calculator\n\nRead hours and hourly rate using two `input()` calls. Convert both to `float`, store them in `hours` and `rate`, compute `pay`, then print `Pay:` and the amount. This chapter uses straight pay for all hours.\n\nFive independent checks are worth 2 XP each. \n\nUse `input()` normally: the checker enters test values for you. Sample inputs, in order: `35`, `2.75`. Input prompts are omitted from captured output.\n\n**Source checkpoint:** Choosing mnemonic variable names; Exercise 3",
      "id": "variables-017"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "# Read hours, read rate, calculate pay, then print.",
      "execution_count": null,
      "outputs": [],
      "id": "variables-018"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## C08 | Temperature converter\n\nRead a Celsius temperature using `input()`, convert it to a float named `celsius`, and compute `fahrenheit = celsius * 9 / 5 + 32`. Print only the Fahrenheit value.\n\nFive independent checks are worth 2 XP each. \n\nUse `input()` normally: the checker enters test values for you. Sample inputs, in order: `0`. Input prompts are omitted from captured output.\n\n**Source checkpoint:** Exercises: Exercise 5",
      "id": "variables-019"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "# Convert Celsius input to Fahrenheit.",
      "execution_count": null,
      "outputs": [],
      "id": "variables-020"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## M01 | Quoted numbers\n\nWhat is the type of `\"3.2\"`?\n\nA. float\nB. int\nC. str\nD. bool",
      "id": "variables-021"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "m01 = \"\"  # A, B, C, or D",
      "execution_count": null,
      "outputs": [],
      "id": "variables-022"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## M02 | A valid name\n\nWhich assignment uses a legal variable name?\n\nA. 2hours = 4\nB. hours_worked = 4\nC. class = 4\nD. hour-rate = 4",
      "id": "variables-023"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "m02 = \"\"  # A, B, C, or D",
      "execution_count": null,
      "outputs": [],
      "id": "variables-024"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## M03 | Assignment output\n\nWhat does a script containing only `x = 5` print?\n\nA. 5\nB. x\nC. None\nD. Nothing",
      "id": "variables-025"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "m03 = \"\"  # A, B, C, or D",
      "execution_count": null,
      "outputs": [],
      "id": "variables-026"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## M04 | True division\n\nIn Python 3, what is `7 / 2`?\n\nA. 3.5\nB. 3\nC. 1\nD. 14",
      "id": "variables-027"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "m04 = \"\"  # A, B, C, or D",
      "execution_count": null,
      "outputs": [],
      "id": "variables-028"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## M05 | Floor division\n\nWhat is `17 // 2`?\n\nA. 8.5\nB. 9\nC. 8\nD. 1",
      "id": "variables-029"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "m05 = \"\"  # A, B, C, or D",
      "execution_count": null,
      "outputs": [],
      "id": "variables-030"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## M06 | Remainder\n\nWhat is `17 % 5`?\n\nA. 3\nB. 2\nC. 0.2\nD. 5",
      "id": "variables-031"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "m06 = \"\"  # A, B, C, or D",
      "execution_count": null,
      "outputs": [],
      "id": "variables-032"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## M07 | Order matters\n\nWhat is `1 + 2 * 5`?\n\nA. 15\nB. 25\nC. 10\nD. 11",
      "id": "variables-033"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "m07 = \"\"  # A, B, C, or D",
      "execution_count": null,
      "outputs": [],
      "id": "variables-034"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## M08 | Input is text\n\nA user types 42 at `input()`. What type is returned?\n\nA. str\nB. int\nC. float\nD. It depends on the digits",
      "id": "variables-035"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "m08 = \"\"  # A, B, C, or D",
      "execution_count": null,
      "outputs": [],
      "id": "variables-036"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## M09 | Joining strings\n\nWhat is `\"10\" + \"15\"`?\n\nA. 25\nB. \"25\"\nC. \"1015\"\nD. An error",
      "id": "variables-037"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "m09 = \"\"  # A, B, C, or D",
      "execution_count": null,
      "outputs": [],
      "id": "variables-038"
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": "## M10 | Useful comments\n\nWhat happens to text after # outside a string on a Python line?\n\nA. It is printed\nB. It is ignored during execution\nC. It becomes a variable\nD. It runs after the next line",
      "id": "variables-039"
    },
    {
      "cell_type": "code",
      "metadata": {},
      "source": "m10 = \"\"  # A, B, C, or D",
      "execution_count": null,
      "outputs": [],
      "id": "variables-040"
    }
  ]
}
