You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
150 lines
3.4 KiB
150 lines
3.4 KiB
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"### \n",
|
|
"\n",
|
|
"# Unit 2 Lab: Control Flow\n",
|
|
"\n",
|
|
"## Overview\n",
|
|
"Welcome to the second unit lab!\n",
|
|
"\n",
|
|
"Right now, you have a variable to hold a movie title, a variable to hold a movie's rating, and a print statement to show the user.\n",
|
|
"\n",
|
|
"Next, let's set up the functions and control flow to print out the values of our variables."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Movie Title\n",
|
|
"\n",
|
|
"This section will remain unchanged for this lab."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 1,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"movie_title = \"Back to the Future\""
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Movie Rating\n",
|
|
"\n",
|
|
"This section will remain unchanged for this lab."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 2,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"movie_rating = 8"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Print the Result\n",
|
|
"\n",
|
|
"Wrap the print statement with a function, `print_ratings`, which:\n",
|
|
"\n",
|
|
"- Takes two arguments:\n",
|
|
" - `movie_list`, a list of movies (assume all string values)\n",
|
|
" - The previously declared variable, `movie_rating`\n",
|
|
"- Iterates through the list of movies and prints `The rating for <movie_title> is <movie_rating>`.\n",
|
|
" - Note that, because we have a single value of `move_rating`, the rating will be the same for all movies. That's okay for now."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 18,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def print_ratings(movie_list, movie_rating=8):\n",
|
|
" for movie in movie_list:\n",
|
|
" print(f\"The rating for {movie} is {movie_rating}.\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"#### Test Your `print_ratings` Function\n",
|
|
"\n",
|
|
"- Create a list of movies, `movie_list`, with the following values:\n",
|
|
" - `\"Back to the Future\"`\n",
|
|
" - `\"Blade\"`\n",
|
|
" - `\"Spirited Away\"`\n",
|
|
"- Call your function, `print_ratings`"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 19,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"The rating for Back to the Future is 8.\n",
|
|
"The rating for Blade is 8.\n",
|
|
"The rating for Spirited Away is 8.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"# A:\n",
|
|
"movie_list = [\n",
|
|
" \"Back to the Future\",\n",
|
|
" \"Blade\",\n",
|
|
" \"Spirited Away\"\n",
|
|
"]\n",
|
|
"\n",
|
|
"print_ratings(movie_list)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"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.6"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|