Basic Python Exercises

See also: Official Python3 Tutorial


Housekeeping

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 executes
  • Escape puts you in command mode
  • Enter puts you in edit mode
  • The H key in command mode brings up help

In [ ]:
# 1. Make your interpreter print the statement "Hello, world!".

In [ ]:
# 2. Assign a string to a variable and then print the variable.

In [ ]:
# 3. Create a list of numbers and print every number in that list.

In [ ]:
# 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:'

In [ ]:
# 5. Create an empty list and add 3 strings to that list.

In [ ]:
# 6. Create a dictionary that links 5 US States with their 2 letter abbreviation.

In [ ]:
# 7. Import the "string" module. Print every character in string.punctuation individually.

In [ ]:
# 8. Read all the information in the text_file.txt in the data folder.

In [ ]:
# 9. Create a string with your name and write it to a file in the data folder.

In [ ]:
# 10. Create a function that prints "Hello, world!".

In [ ]:
# 11. Import os and use os.walk to read and print the contents of every file in data/dir_tree.

In [ ]:
# 12. Use a range() object to print the numbers from 1 through 10.