Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution #1

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
37 changes: 37 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Contributing to Learn.co Curriculum

We're really exited that you're about to contribute to the [open curriculum](https://learn.co/content-license) on [Learn.co](https://learn.co). If this is your first time contributing, please continue reading to learn how to make the most meaningful and useful impact possible.

## Raising an Issue to Encourage a Contribution

If you notice a problem with the curriculum that you believe needs improvement
but you're unable to make the change yourself, you should raise a Github issue
containing a clear description of the problem. Include relevant snippets of
the content and/or screenshots if applicable. Curriculum owners regularly review
issue lists and your issue will be prioritized and addressed as appropriate.

## Submitting a Pull Request to Suggest an Improvement

If you see an opportunity for improvement and can make the change yourself go
ahead and use a typical git workflow to make it happen:

* Fork this curriculum repository
* Make the change on your fork, with descriptive commits in the standard format
* Open a Pull Request against this repo

A curriculum owner will review your change and approve or comment on it in due
course.

# Why Contribute?

Curriculum on Learn is publicly and freely available under Learn's
[Educational Content License](https://learn.co/content-license). By
embracing an open-source contribution model, our goal is for the curriculum
on Learn to become, in time, the best educational content the world has
ever seen.

We need help from the community of Learners to maintain and improve the
educational content. Everything from fixing typos, to correcting
out-dated information, to improving exposition, to adding better examples,
to fixing tests—all contributions to making the curriculum more effective are
welcome.
23 changes: 23 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Learn.co Educational Content License

Copyright (c) 2018 Flatiron School, Inc

The Flatiron School, Inc. owns this Educational Content. However, the Flatiron
School supports the development and availability of educational materials in
the public domain. Therefore, the Flatiron School grants Users of the Flatiron
Educational Content set forth in this repository certain rights to reuse, build
upon and share such Educational Content subject to the terms of the Educational
Content License set forth [here](http://learn.co/content-license)
(http://learn.co/content-license). You must read carefully the terms and
conditions contained in the Educational Content License as such terms govern
access to and use of the Educational Content.

Flatiron School is willing to allow you access to and use of the Educational
Content only on the condition that you accept all of the terms and conditions
contained in the Educational Content License set forth
[here](http://learn.co/content-license) (http://learn.co/content-license). By
accessing and/or using the Educational Content, you are agreeing to all of the
terms and conditions contained in the Educational Content License. If you do
not agree to any or all of the terms of the Educational Content License, you
are prohibited from accessing, reviewing or using in any way the Educational
Content.
114 changes: 74 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,101 +1,135 @@

# Practice with datatypes
# Practice with Data Types

### Introduction
## Introduction

In the past few lessons, we have learned about working with different types of data in Python: strings, numbers (ints and floats), and booleans. Now let's put that knowledge into action.
In the past few lessons, you learned about working with different types of data in Python: strings, numbers (ints and floats), and booleans. Now, you'll put that knowledge into action.

In this lesson we'll imagine that we were at a nice social gathering and exchanged business cards with a few people. One of the business cards belongs to Art Vandelay, a new travel agent. We want to use our programming skills to format this information correctly.
Imagine that you're at a business event and exchanged business cards with a few people. One of the business cards belongs to Art Vandelay, a new travel agent. Here, you'll use your programming skills to format this information correctly.

### Learning Objectives
## Learning Objectives
* Manipulate strings with built-in methods
* Practice coercing data types and changing numbers

### Here to mingle
## Here to mingle

The next morning we take out the business card, ready to format it using our programming skills, and here is what we find.
The next morning you take out the business card, ready to format it using your programming skills, and here is what we find.

![](https://learn-verified.s3.amazonaws.com/data-science-assets/biz-card-mistakes.jpg)

Yea, Mr. Vandelay may not be the best person to get to know or the best at designing business cards, but like Mr. Vandelay, we know that people misenter information on forms all the time.
## String Transformations

So as data scientists, we often need to clean and organize data before we can make sense of it. Let's get to work.
When storing text in a spreadsheet or database programmatically, you will often preprocess the data to ensure that it is properly formatted. For example, you might ensure that a telephone number matches the required format, or that a field on a web form is filled out.

### Solving our first lab

This is our first lab, and here we'll see that there is some data already provided for us. Next to the data, we will see a comment indicating what the data should look like after we change it.

For example, let's say we want to capitalize all of the letters of "art vandlay". We'll see the following:
Here's a simple example of how you might go about doing this:


```python
"art vandelay" # "ART VANDELAY"
name = "art vandelay" # "ART VANDELAY"
name.upper()
```

Notice that there is no output below the gray code above. This is because Jupyter notebooks do not automatically run our code - so they do not automatically know the output. To display the output, we must **run** the code by clicking on the gray cell and then pressing shift + enter. Let's try it in the cell above and see our output appear below.

Ok, once we see the output take a look at the cell below with the hash tag to the right of the string, `'hello'`. This is a comment like the above. Comments are used for programmers to annotate their code, but a comment has no impact on the code. We can see this by running the cell below (again, press shift + enter).


'ART VANDELAY'



If you haven't already, put your cursor into the cell above and press `shift + enter` to run the code in the cell. You should see an updated output produced by the `.upper()` string method.

Another important note is the hashtag `#`. In python, hashtags indicate a comment. Comments are notes used to provide additional information but are ignored by the computer when running the code.


```python
'hello' ### whattttt
```

After pressing shift+enter on the cell above, we see that still Python happily ignores our comment. So here (and in future labs), a comment will be provided to indicate what we should see as the return value of our code. When we press shift+enter, and the output below matches the comment to the right of our code, we did it correctly.

> In future labs, Learn will check our code to ensure that we did it correctly. But for our first lab, this works fine.

To get our output to match the comment we will change it to the following:

'hello'

```python
"art vandelay".upper() # 'ART VANDELAY'
```

### Get going with strings

First use the `title` method to capitalize the first letter of each word in "art vandelay"`.
After pressing shift+enter on the cell above, you'll see that Python ignores the comment. In Flatiron coding labs, a comment will be provided to indicate what you are aiming to have the code return. This allows you to then easily check your answer upon running your code.

## Get going with strings

```python
"art vandelay" # 'Art Vandelay'
```
With that, use the appropriate string method to transform each string to match the desired output in the comment.

Now let's uppercase all of the letters of "Ceo".
Use the `title` method to capitalize the first letter of each word in "art vandelay"`.


```python
"Ceo" # 'CEO'
"art vandelay".title() # 'Art Vandelay'
```

Next, write a method that answers a question about our email addresses. Every email address should end with ".com". We can use our knowledge of string methods to check if the email address ends with ".com" and return `True` or `False` accordingly.



'Art Vandelay'



Now use the `upper` method to capitalize all of the letters of "Ceo".


```python
"[email protected]" # False
"Ceo".upper() # 'CEO'
```

As you can see below, the website "vandelay.com" is not preceded by `"www."`. We can perform what is called string interpolation to fix this! Use the plus sign, `'+'`, to change the website `'vandelay.com'` to the string `'www.vandelay.com'` by prepending `'www.'`.



'CEO'



Next, write a method that verifies whether an email addresses is valid. To make this introductory example simple, assume that every email address should end with ".com". With that, use your knowledge of string methods to check if the email address ends with ".com" and return `True` or `False` accordingly.


```python
'vandelay.com' # 'www.vandelay.com'
"art.vandelay@vandelay.co".endswith('.com') # False
```

### Working with numbers

Finally, Mr. Vandelay gave us his phone number, but he actually has two other phone numbers that are different from the one listed. All three numbers are basically the same with the excepion of the ending. Below, start by coercing the first phone number, which is currently a string, to an `int` and add one. Next do the same to the second phone number but increase it by two.


False



As you can see below, the website "vandelay.com" is not preceded by `"www."`. You can perform string concatenation to fix this! string concatenation allows you to join two strings. It works just like numerical addition. For example, ```"This is the start" + "and this is the end"``` would return ```"This is the start and this is the end"```. Use string concatenation to change the website `'vandelay.com'` to the string `'www.vandelay.com'` by prepending `'www.'`.


```python
"7285553334" # 7285553335
'www.' + 'vandelay.com' # 'www.vandelay.com'
```




'www.vandelay.com'



## String Slicing

Finally, Mr. Vandelay gave us his phone number. Extract the area code by selecting the first three characters of the string. You can do this using brackets to select characters from the string as in ```"George"[:4]``` which would return ```"Geor"```.


```python
"7285553334" # 7285553336
"7285553334"[:3] # 728
```

### Summary

Our first lab is done! Sweet. In this lab, we practiced working with string methods to operate on and answer questions about strings. We wrote methods that return Booleans and changed strings to intergers in order to perform addition. So much of working with data is ensuring that it is properly formatted so we can then operate on it, and in this lab, we saw how to use code to do just that.


'728'



## Summary

Congratulations! You just completed your first lab! You practiced working with string methods to operate on and answer questions about strings. You also used methods that return Booleans and sliced strings. So much of working with data is ensuring that it is properly formatted and in this lab, you started practicing your data wrangling skills.
6 changes: 6 additions & 0 deletions future_tests/index_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import unittest2 as unittest
from ipynb.fs.full.index import *

class TestPythonDatatypes(unittest.TestCase):
def test_passes(self):
self.assertEqual(True, True)
Loading