We've completed the "Overview" section of the presentation and we're now doing the in-depth examination of the packages presented. Because of the varying levels of skill of the people on this call, I can't really ensure that I'm giving you the information you need. If what I'm doing is not helpful, feel free to explore the web for other Python resources (I'd start with the items at the bottom of each notebook in the "Other Links" section).
Even if you're not working on the specific section I am, please feel free to ask/send me questions.
There's no shame in Googling things. Stack Overflow is your friend.
Reminders:
Shift + Enter executesEscape puts you in command modeEnter puts you in edit modeH key in command mode brings up help
In [1]:
# 1. Make your interpreter print the statement "Hello, world!".
print('Hello, World!')
In [2]:
# 2. Assign a string to a variable and then print the variable.
a = 'My string'
print(a)
In [3]:
# 3. Create a list of numbers and print every number in that list.
list_o_numbers = [1,2,3,45]
for item in list_o_numbers:
print(item)
In [4]:
# 4. Create a list of numbers and print the numbers if the number is greater than 3.
# Hint: remember to indent conditionals like 'if condition:'
for item in list_o_numbers:
if item > 3:
print(item)
In [5]:
# 5. Create an empty list and add 3 strings to that list.
new_list = [] # list()
new_list.append(1)
new_list.append(2)
new_list.append(3)
print(new_list)
In [1]:
# 6. Create a dictionary that links 5 US States with their 2 letter abbreviation.
dictionary = {'MO': 'Missouri', 'MN': 'Minnesota'}
dictionary
Out[1]:
In [3]:
# 7. Import the "string" module. Print every character in string.punctuation individually.
import string
for character in string.punctuation:
print(character, end='\t')
In [10]:
# 8. Read all the information in the text_file.txt in the data folder.
with open('data/text_file.txt') as f:
data = f.read()
print(data)
In [11]:
# 9. Create a string with your name and write it to a file in the data folder.
with open('data/text_file_new.txt', 'w+') as f:
f.write('Theo')
In [12]:
# 10. Create a function that prints "Hello, world!".
def hello():
print('Hello, world!')
hello()
In [14]:
# 11. Import os and use os.walk to read and print the contents of every file in data/dir_tree.
import os
for root, folder_names, file_names in os.walk('data/dir_tree/'):
for file_name in file_names:
path = os.path.join(root, file_name)
with open(path, 'r') as f:
print(f.read())
In [4]:
# 12. Use a range() object to print the numbers from 1 through 10.
for x in range(0, 11):
print(x)