Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,744 changes: 940 additions & 804 deletions 01_materials/slides/03_functions.ipynb

Large diffs are not rendered by default.

1,901 changes: 1,148 additions & 753 deletions 01_materials/slides/04_strings.ipynb

Large diffs are not rendered by default.

570 changes: 347 additions & 223 deletions 01_materials/slides/05_converting_types.ipynb

Large diffs are not rendered by default.

276 changes: 153 additions & 123 deletions 01_materials/slides/06_inputs.ipynb
Original file line number Diff line number Diff line change
@@ -1,133 +1,163 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "5645a11c",
"metadata": {
"id": "5645a11c"
},
"source": [
"# Input"
]
},
{
"cell_type": "markdown",
"id": "ca2ed9ad",
"metadata": {},
"source": [
"## Contents:\n",
"1. Getting user input"
]
},
{
"cell_type": "markdown",
"id": "3ac38293",
"metadata": {
"id": "3ac38293"
},
"source": [
"## Getting user input\n",
"\n",
"Sometimes, we may want to work with data given to us by the user running the program. One way to get user input is with the `input()` function, which prompts the user and returns their response as a string. `input()` takes a prompt string as an argument.\n",
"\n",
"Be careful when using `input()` -- there's no guarantee that the user will answer in a way you expect!"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69f1ae7d",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 52
},
"id": "69f1ae7d",
"outputId": "eef68880-b940-4f06-ab27-fd3e6ea9a7cd"
},
"outputs": [],
"source": [
"age = input('How old are you? ')\n",
"age"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b81e701c",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "b81e701c",
"outputId": "7524c0f2-64da-4907-b682-dd132e8b7dea"
},
"outputs": [],
"source": [
"# to do arithmetic on an input, we need to convert it\n",
"age_next_bday = int(age) + 1\n",
"print('Next birthday you will be {}'.format(age_next_bday))"
]
},
{
"cell_type": "markdown",
"id": "d2e043ce",
"metadata": {},
"source": [
"## Exercise\n",
"Create a program to take in a first name, then a last name as two inputs, and output it them together as a full name."
]
"cells": [
{
"cell_type": "markdown",
"id": "5645a11c",
"metadata": {
"id": "5645a11c"
},
"source": [
"# Input"
]
},
{
"cell_type": "markdown",
"id": "ca2ed9ad",
"metadata": {},
"source": [
"## Contents:\n",
"1. Getting user input"
]
},
{
"cell_type": "markdown",
"id": "3ac38293",
"metadata": {
"id": "3ac38293"
},
"source": [
"## Getting user input\n",
"\n",
"Sometimes, we may want to work with data given to us by the user running the program. One way to get user input is with the `input()` function, which prompts the user and returns their response as a string. `input()` takes a prompt string as an argument.\n",
"\n",
"Be careful when using `input()` -- there's no guarantee that the user will answer in a way you expect!"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "69f1ae7d",
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/",
"height": 52
},
"id": "69f1ae7d",
"outputId": "eef68880-b940-4f06-ab27-fd3e6ea9a7cd"
},
"outputs": [
{
"cell_type": "code",
"execution_count": null,
"id": "d4349146",
"metadata": {},
"outputs": [],
"source": [
"# Your code goes here"
"data": {
"text/plain": [
"'10'"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"metadata": {
"celltoolbar": "Slideshow",
],
"source": [
"age = input('How old are you? ')\n",
"age"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "b81e701c",
"metadata": {
"colab": {
"collapsed_sections": [
"0294d7fe",
"b3f69e98",
"cd134d80",
"16f27979",
"f1caca54",
"3a700ac7",
"722d2c13",
"ed8b70b9"
],
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"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.11.5"
"base_uri": "https://localhost:8080/"
},
"rise": {
"scroll": true,
"theme": "solarized",
"transition": "none"
"id": "b81e701c",
"outputId": "7524c0f2-64da-4907-b682-dd132e8b7dea"
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Next birthday you will be 11\n"
]
}
],
"source": [
"# to do arithmetic on an input, we need to convert it\n",
"age_next_bday = int(age) + 1\n",
"print('Next birthday you will be {}'.format(age_next_bday))"
]
},
{
"cell_type": "markdown",
"id": "d2e043ce",
"metadata": {},
"source": [
"## Exercise\n",
"Create a program to take in a first name, then a last name as two inputs, and output it them together as a full name."
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "d4349146",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Your full name is Vikram Katju\n"
]
}
],
"source": [
"# Your code goes here\n",
"first_name = input('What is your first name? ')\n",
"last_name = input ('What is your last name? ')\n",
"print ('Your full name is', first_name + ' ' + last_name)"
]
}
],
"metadata": {
"celltoolbar": "Slideshow",
"colab": {
"collapsed_sections": [
"0294d7fe",
"b3f69e98",
"cd134d80",
"16f27979",
"f1caca54",
"3a700ac7",
"722d2c13",
"ed8b70b9"
],
"provenance": [],
"toc_visible": true
},
"kernelspec": {
"display_name": "dsi_participant",
"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.9.20"
},
"nbformat": 4,
"nbformat_minor": 5
"rise": {
"scroll": true,
"theme": "solarized",
"transition": "none"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading