{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.2 \u2014 Input/Output & f-strings\n",
    "\n",
    "So far every value in your programs has been typed directly into the code. Today your programs start listening: `input()` lets a person type something back, and f-strings are the clean way to weave that (or any variable) into a sentence."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## The Idea\n",
    "\n",
    "`input(\"prompt\")` pauses your program, shows the prompt, and waits for the player to type something and hit Enter. Whatever they type comes back as a **string** \u2014 always, even if they typed a number.\n",
    "\n",
    "```python\n",
    "player_name = input(\"What's your name, adventurer? \")\n",
    "```\n",
    "\n",
    "An **f-string** lets you drop variables straight into a sentence \u2014 put an `f` right before the opening quote, and wrap each variable in `{ }`:\n",
    "\n",
    "```python\n",
    "print(f\"Welcome, {player_name}!\")\n",
    "```\n",
    "\n",
    "If you need a number instead of text, wrap `input()` in `int()` or `float()` to convert it:\n",
    "\n",
    "```python\n",
    "starting_gold = int(input(\"How much gold do you start with? \"))\n",
    "```"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# A worked example \u2014 greeting Zara at the start of the adventure\n",
    "\n",
    "player_name = input(\"What's your name, adventurer? \")\n",
    "starting_gold = int(input(\"How much gold do you start with? \"))\n",
    "\n",
    "print(f\"Welcome, {player_name}!\")\n",
    "print(f\"You set out with {starting_gold} gold in your pocket.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "*Watch out for:* `input()` **always** hands back a string, even if the player types `100`. Try to add two un-converted inputs together and you'll get string concatenation (`\"10\" + \"5\"` gives `\"105\"`, not `15`) instead of addition \u2014 wrap numeric input in `int()` or `float()` the moment you read it."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Guided Practice 1\n",
    "\n",
    "Old Finn wants to know a bit about you before he joins your party. Run the cell as-is, then change the prompts or add a line of your own."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Old Finn asks a few questions \u2014 change the prompts below and re-run\n",
    "\n",
    "favorite_weapon = input(\"Old Finn asks: what's your weapon of choice? \")\n",
    "print(f\"Old Finn nods. \\\"A {favorite_weapon}? Good choice.\\\"\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Guided Practice 2\n",
    "\n",
    "The monster blocking your path wants to know what it's dealing with. Fill in every `____` \u2014 one line reads input, the next uses it in an f-string."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Replace every ____ with the right function name (input or int)\n",
    "\n",
    "character_class = ____(\"What's your class? \")        # fill in: the function that reads text\n",
    "print(f\"You face the monster as a {character_class}.\")\n",
    "\n",
    "health = ____(____(\"What's your starting health? \"))  # fill in: convert-to-number, then read-text\n",
    "print(f\"You enter battle with {health} health.\")\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Independent Practice 1\n",
    "\n",
    "Zara just found a weapon. Ask the player to name it (`input()`), then ask how much damage it deals (convert to `int` or `float`). Print a sentence using an f-string that includes both.\n",
    "\n",
    "**Hint (only if stuck):** it's the same two-line pattern as the worked example \u2014 `input()` for the name, `int(input())` for the number, then one `print(f\"...\")` using both."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Your code here \u2014 ask for a weapon name and its damage, then print a message with an f-string\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Independent Practice 2\n",
    "\n",
    "No hint this time. Ask the player to describe the room Zara just entered (a short description as a string) and how many monsters are in it (a number). Print a two-line status update using f-strings \u2014 one line for the description, one for the monster count."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Your code here \u2014 ask about the room, then print an f-string status update\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Want More? (Optional)\n",
    "\n",
    "Ask for the room description, the monster count, *and* Zara's current health, then print all three in a single f-string on one line, formatted like a status bar: `Room: <desc> | Monsters: <n> | Health: <hp>`"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# Optional stretch \u2014 combine three inputs into one status-bar-style f-string\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Check Your Understanding\n",
    "\n",
    "In one sentence: why do you need `int()` around `input()` when you want a number, but not when you want text?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**Your answer:** *(double-click to edit this cell)*"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.11"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
