Editing Community Data Science Workshops (Core)/Day 0 Tutorial
From CommunityData
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
Welcome to the Friday tutorial! | |||
Welcome to the tutorial! | |||
This tutorial covers several core programming concepts that we'll build upon during an interactive lecture tomorrow morning. It will take 1-2 hours to complete. There's a break in the middle, and exercises at the middle and end to help review the material. | This tutorial covers several core programming concepts that we'll build upon during an interactive lecture tomorrow morning. It will take 1-2 hours to complete. There's a break in the middle, and exercises at the middle and end to help review the material. | ||
To get started, fire up a new Jupyter notebook. Name it as you like. | To get started, fire up a new Jupyter notebook. Name it as you like. | ||
This is an interactive tutorial! As you go through this tutorial, any time you see something that looks like this: | This is an interactive tutorial! As you go through this tutorial, any time you see something that looks like this: | ||
Line 154: | Line 150: | ||
You can reassign variables if you want. What do you think will print if you type in: | You can reassign variables if you want. What do you think will print if you type in: | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
x = 4 | x = 4 | ||
x | x | ||
x = 5 | x = 5 | ||
x | x | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 168: | Line 158: | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
x = 3 | x = 3 | ||
y = 4 | y = 4 | ||
x * y | x * y | ||
x * x | x * x | ||
2 * x - 1 * y | 2 * x - 1 * y | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 284: | Line 266: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
len("") | len("") | ||
fish = "humuhumunukunukuapua'a" | fish = "humuhumunukunukuapua'a" | ||
name_length = len(fish) | name_length = len(fish) | ||
fish + " is a Hawaiian fish whose name is " + str(name_length) + " characters long." | fish + " is a Hawaiian fish whose name is " + str(name_length) + " characters long." | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 321: | Line 297: | ||
One fun thing about strings in Python is that you can multiply them: | One fun thing about strings in Python is that you can multiply them: | ||
<syntaxhighlight lang="python"> | <syntaxhighlight lang="python"> | ||
"A" * 40 | "A" * 40 | ||
"ABC" * 12 | |||
"ABC" * 12 | |||
h = "Happy" | h = "Happy" | ||
b = "Birthday" | b = "Birthday" | ||
Line 341: | Line 314: | ||
total = 1.5 - 1/2 | total = 1.5 - 1/2 | ||
total | total | ||
type(total) | |||
</syntaxhighlight> | </syntaxhighlight> | ||
Line 349: | Line 322: | ||
b = "brown" | b = "brown" | ||
c = "fox jumps over the lazy dog" | c = "fox jumps over the lazy dog" | ||
"The " + a * 3 + " " + b * 3 + " " + c | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==End of Part 1== | ==End of Part 1== | ||
Line 385: | Line 357: | ||
<code>if 6 > 5:</code><br /> | <code>if 6 > 5:</code><br /> | ||
<br /> | <br /> | ||
part, and press Enter. | part, and press Enter. The next line will have <code>...</code> as a prompt, instead of the usual <code>>>></code>. This is Python telling us that we are in the middle of a '''code block''', and so long as we indent our code it should be a part of this code block.</li> | ||
< | <li>Press the spacebar 4 times to indent.</li> | ||
<li>Type<br /> | <li>Type<br /> | ||
<br /> | <br /> | ||
<code>print("Six is greater than five!")</code><br /><br /></li> | <code>print("Six is greater than five!")</code><br /><br /></li> | ||
< | <li>Press Enter to end the line. The prompt will still be a <code>...</code></li> | ||
<li>Press | <li>Press Enter one more time to tell Python you are done with this code block. The code block will now execute.</li> | ||
</ol> | </ol> | ||
Line 584: | Line 555: | ||
===I was expecting python to print lots of lines of text when I ran this cell, but it only prints one line!=== | ===I was expecting python to print lots of lines of text when I ran this cell, but it only prints one line!=== | ||
Jupyter only outputs the last line of a code chunk unless you explicitly wrap the code in print() statements. If you split your code into multiple chunks or print() the line, it should look like you expect. | Jupyter only outputs the last line of a code chunk unless you explicitly wrap the code in print() statements. If you split your code into multiple chunks or print() the line, it should look like you expect. | ||
[[Category:Shared_Pages]] | [[Category:Shared_Pages]] | ||
[[Category:CDSW]] | [[Category:CDSW]] |