Skip to content

Commit 7fb508f

Browse files
authored
Merge pull request UofT-DSI#29 from UofT-DSI/update
Update homework
2 parents 46f88ea + 67872fa commit 7fb508f

12 files changed

Lines changed: 120 additions & 3 deletions
File renamed without changes.
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"metadata": {},
6+
"source": [
7+
"# Jupyter Notebooks\n",
8+
"Jupyter Notebooks are web applications that lets us combine pieces of executable code, text, images, and visualizations in a single document, or notebook. We have installed a Jupyter Extension that lets us run notebooks directly in Visual Studio Code (VS Code)."
9+
]
10+
},
11+
{
12+
"cell_type": "markdown",
13+
"metadata": {},
14+
"source": [
15+
"Sections of a notebook are called cells. Cells can be run independently of each other, and in any order."
16+
]
17+
},
18+
{
19+
"cell_type": "markdown",
20+
"metadata": {},
21+
"source": [
22+
"## Adding text\n",
23+
"\n",
24+
"Notebooks use markdown, a markup language, for formatting text. IBM publishes a [Jupyter-specific markdown cheat sheet](https://www.ibm.com/docs/en/watson-studio-local/1.2.3?topic=notebooks-markdown-jupyter-cheatsheet).\n",
25+
"\n",
26+
"To add a text cell:\n",
27+
"1. Click **+ Markdown**\n",
28+
"2. Add some text. When you are done editing, press `ctrl` + `enter` to run the cell and format your text."
29+
]
30+
},
31+
{
32+
"cell_type": "markdown",
33+
"metadata": {},
34+
"source": [
35+
"To use VS Code with the Jupyter extension for writing and running code, follow these modified steps:\n",
36+
"\n",
37+
"## Writing and Running Code in VS Code with Jupyter Extension\n",
38+
"\n",
39+
"1. **Writing Code Cells:**\n",
40+
" - Use code cells to write your Python code. To create a new code cell, click on the `+ Code` button in the Jupyter toolbar.\n",
41+
" - Type or paste your Python code within the code cell.\n",
42+
"\n",
43+
"2. **Running Code Cells:**\n",
44+
" - To execute a code cell, you can:\n",
45+
" - Click the `Run Cell` button (a triangle icon) in the Jupyter toolbar.\n",
46+
" - Use the keyboard shortcut `Shift + Enter`.\n",
47+
" - Output, if any, will be displayed below the cell after execution.\n",
48+
"\n",
49+
"3. **Keyboard Shortcuts:**\n",
50+
" - Utilize keyboard shortcuts for faster execution:\n",
51+
" - `Shift + Enter`: Run the current cell and move to the next cell.\n",
52+
" - `Ctrl + Enter`: Run the current cell and stay on the same cell.\n",
53+
" - `Alt + Enter`: Run the current cell and insert a new cell below.\n",
54+
"\n",
55+
"4. **Code Assistance and Auto-completion:**\n",
56+
" - The Jupyter extension in VS Code offers code assistance and auto-completion. Press `Tab` for suggestions while writing code.\n",
57+
"\n",
58+
"5. **Saving and Renaming:**\n",
59+
" - Save your Jupyter notebook by clicking on `File` > `Save` or `File` > `Save As...`.\n",
60+
" - To rename the notebook, right-click on the notebook file in the file explorer on the left and select `Rename`.\n",
61+
"\n",
62+
"6. **Managing Cells:**\n",
63+
" - Use the `+ Code` or `+ Markdown` buttons in the Jupyter toolbar to add new code or text cells, respectively.\n",
64+
" - You can rearrange the order of cells by clicking and dragging them in the Jupyter notebook.\n",
65+
" - Right-click on a cell in the Jupyter notebook to access options like deleting or moving the cell."
66+
]
67+
},
68+
{
69+
"cell_type": "markdown",
70+
"metadata": {},
71+
"source": [
72+
"No problem! If you won't be using Google Colab or Drive, and you want to work exclusively in Visual Studio Code, here are modified instructions:\n",
73+
"\n",
74+
"## Instructions for Accessing and Using the `data` Folder in Visual Studio Code\n",
75+
"\n",
76+
"1. **Access GitHub Repository:**\n",
77+
" - Go to your GitHub repository where the `data` folder is located: [https://github.com/UofT-DSI/python](https://github.com/UofT-DSI/python)\n",
78+
" - Clone the repository to your local machine using the following command in your terminal or command prompt:\n",
79+
" ```\n",
80+
" git clone https://github.com/UofT-DSI/python.git\n",
81+
" ```\n",
82+
" - Navigate to the cloned repository on your local machine.\n",
83+
"\n",
84+
"2. **Access and Use the `data` Folder in Visual Studio Code:**\n",
85+
" - Open Visual Studio Code.\n",
86+
" - Open the folder corresponding to the cloned GitHub repository using the \"File\" > \"Open Folder...\" menu option.\n",
87+
" - You should now see the `data` folder in your Visual Studio Code workspace.\n",
88+
"\n",
89+
"3. **Working with the `data` Folder:**\n",
90+
" - You can access and use the contents of the `data` folder directly in your Python scripts or Jupyter notebooks within Visual Studio Code. For example, you can read data from files in the `data` folder using Python's file handling functions or libraries like Pandas."
91+
]
92+
},
93+
{
94+
"cell_type": "markdown",
95+
"metadata": {},
96+
"source": [
97+
"### What is Python?\n",
98+
"\n",
99+
"Python is a general-purpose programming language first released in 1991. It has since become a popular language for data science, thanks to an enthusiastic community and a large ecosystem of code libraries and tools that make it easier to perform common tasks throughout the data science life cycle."
100+
]
101+
}
102+
],
103+
"metadata": {
104+
"kernelspec": {
105+
"display_name": "dsi_participant",
106+
"language": "python",
107+
"name": "python3"
108+
},
109+
"language_info": {
110+
"name": "python",
111+
"version": "3.11.8"
112+
}
113+
},
114+
"nbformat": 4,
115+
"nbformat_minor": 2
116+
}

03_homework/04_inputs.ipynb

Lines changed: 0 additions & 1 deletion
This file was deleted.

03_homework/07_inputs.ipynb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"cells":[{"cell_type":"markdown","metadata":{"id":"cxCHAm0GXfFb"},"source":["# Inputs\n","## Practice Problems"]},{"cell_type":"markdown","metadata":{"id":"DbzTxpsposCe"},"source":["### 1. Write a Python program that asks the user for their name using the `input()` function and then greets them with a personalized message. Ensure that the program displays the user's name exactly as entered.\n","\n","Example:\n","```\n","Enter your name: John\n","Hello, John! Nice to meet you.\n","```\n"]},{"cell_type":"code","execution_count":null,"metadata":{"id":"p5sB4WjWh2Tp"},"outputs":[],"source":["# Your code goes here"]},{"cell_type":"markdown","metadata":{},"source":["<details>\n"," <summary>Answer</summary>\n","\n"," ```python\n"," # Ask the user for their name\n"," name = input(\"Enter your name: \")\n","\n"," # Greet the user with a personalized message\n"," print(\"Hello, \" + name + \"! Nice to meet you.\")\n","\n"," ```\n","</details>"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyO3VijQCXDe7a1I0vgK92JH","collapsed_sections":[],"provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"cells":[{"cell_type":"markdown","metadata":{"id":"cxCHAm0GXfFb"},"source":["# Reading and Writing\n","## Practice Problems"]},{"cell_type":"markdown","metadata":{"id":"XUiaOKuWdLcW"},"source":["### 1. Using `w`, create a file called `fruits.txt` and write the string \"tangerines\" to it. Next, use `a` to append the string \"dragon fruit\" to the file on a new line. Finally, use `r` to read and print the entire file. "]},{"cell_type":"code","execution_count":null,"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"executionInfo":{"elapsed":15,"status":"ok","timestamp":1668131109930,"user":{"displayName":"Kaylie Lau","userId":"01284785813595846851"},"user_tz":300},"id":"T_4K-JAteH6S","outputId":"766d459e-3aba-421a-cf9c-418132dce45e"},"outputs":[{"name":"stdout","output_type":"stream","text":["tangerines\n","dragon fruit\n"]}],"source":["# Your code goes here"]},{"cell_type":"markdown","metadata":{},"source":["<details>\n"," <summary>Answer</summary>\n","\n"," ```python\n"," with open('fruits.txt', 'w') as fruit_file:\n"," fruit_file.write('tangerines')\n","\n"," with open('fruits.txt', 'a') as fruit_file:\n"," fruit_file.write('\\ndragon fruit')\n","\n"," with open('fruits.txt', 'r') as fruit_file:\n"," print(fruit_file.read())\n"," ```\n","</details>"]}],"metadata":{"colab":{"authorship_tag":"ABX9TyO3VijQCXDe7a1I0vgK92JH","collapsed_sections":[],"provenance":[]},"kernelspec":{"display_name":"Python 3","name":"python3"},"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":0}
File renamed without changes.

0 commit comments

Comments
 (0)