Skip to content

Commit 6e04fbf

Browse files
committed
Add Lesson 6: Books
1 parent 359c3f9 commit 6e04fbf

File tree

3 files changed

+145
-6
lines changed

3 files changed

+145
-6
lines changed

lessons/lesson_6_books/index.html

Lines changed: 70 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@
55
<!--Import Google Icon Font-->
66
<link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
77
<!--Import materialize.css-->
8-
<link type="text/css" rel="stylesheet" href="../../css/materialize.min.css" media="screen,projection"/>
8+
<link type="text/css" rel="stylesheet" href="../../style/css/materialize.min.css" media="screen,projection"/>
99

1010
<!--Add favicon-->
11-
<link rel="shortcut icon" href="../../assets/favicon.ico" type="image/x-icon"/>
11+
<link rel="shortcut icon" href="../../style/assets/favicon.ico" type="image/x-icon"/>
1212

1313
<!--Let browser know website is optimized for mobile-->
1414
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
15-
<link href="../../css/main.css" media="screen" rel="stylesheet">
15+
<link href="../../style/css/main.css" media="screen" rel="stylesheet">
1616

1717
</head>
1818
<body>
1919
<script type="text/javascript" src="https://code.jquery.com/jquery-2.1.1.min.js"></script>
20-
<script type="text/javascript" src="../../js/materialize.min.js"></script>
21-
<script type="text/javascript" src="../../js/main.js"></script>
20+
<script type="text/javascript" src="../../style/js/materialize.min.js"></script>
21+
<script type="text/javascript" src="../../style/js/main.js"></script>
2222

2323
<nav>
2424
<div class="nav-wrapper indigo darken-2">
@@ -61,12 +61,76 @@
6161
<li><a href="../lesson_6_books/index.html">Lesson 6: Books</a></li>
6262
<li><a href="../lesson_7_anagrams/index.html">Lesson 7: Anagrams</a></li>
6363
</ul>
64-
<h3></h3>
64+
<h3>Overview</h3>
6565
<div class="row">
6666
<div class="col s12 m12 l6">
6767
<div class="card indigo lighten-5">
6868
<div class="card-content black-text">
69+
<p>
70+
Capitalizing the title of books and articles can be a bit tricky in English. There are a couple
71+
finnicky rules that mean you can't just capitalize every word and call it a day.
72+
</p>
6973

74+
<p>
75+
This lesson we're going to create a <code class="inline">Class</code> called <code
76+
class="inline">Book</code>. This class should take in a single <em>parameter</em> when
77+
<em>initialize</em>. This will be a <code class="inline">string</code> with the book's title.
78+
</p>
79+
80+
<p>
81+
You should then set the book's <code class="inline">title</code> attribute equal to the
82+
correctly "titleized" version of the input string.
83+
</p>
84+
</div>
85+
</div>
86+
</div>
87+
</div>
88+
89+
<h3>Lesson Objectives</h3>
90+
<div class="row">
91+
<div class="col s12 m12 l6">
92+
<div class="card indigo lighten-5">
93+
<div class="card-content black-text">
94+
<ol class="browser-default">
95+
<li>Read official Python documentation</li>
96+
<li>Learn how to create a <code class="inline">Class</code></li>
97+
<li>String manipulation</li>
98+
<li>Setting variables on an <em>instance</em> of a <code class="inline">Class</code>.</li>
99+
</ol>
100+
</div>
101+
</div>
102+
</div>
103+
</div>
104+
105+
<h3>Challenge Rules</h3>
106+
<div class="row">
107+
<div class="col s12 m12 l6">
108+
<div class="card indigo lighten-5">
109+
<div class="card-content black-text">
110+
<ul class="browser-default">
111+
<li>
112+
Create a class called <code class="inline">Book</code> that takes in a single string when
113+
initialized
114+
</li>
115+
<li>
116+
Create a function inside your Book class that correctly "titleizes" the string according to
117+
the following rules:
118+
<ol class="browser-default">
119+
<li>Capitalize the first and last word</li>
120+
<li>Capitalize nouns, pronouns, adjectives, verbs, adverbs, and subordinate conjunctions
121+
(although, because)
122+
</li>
123+
<li>Lowercase articles (a, an, the), coordinating conjunctions (and, but or), and
124+
prepositions
125+
</li>
126+
<li>Lowercase the 'to' in an infinitive (Let's Learn to Play Chess)</li>
127+
</ol>
128+
</li>
129+
<li>
130+
Assign the "titleized" string to an instance variable in <code class="inline">Book</code>
131+
called <code class="inline">title</code>.
132+
</li>
133+
</ul>
70134
</div>
71135
</div>
72136
</div>
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# English conventions for capitalizing titles can be a bit tricky. In this lesson you'll work on putting
2+
# some of these finnicky rules into practice.
3+
# Create a Book class that accepts a string parameter - the book's title - and assigns the correctly capitalized
4+
# version of that title as a `Book.title` attribute.
5+
# This is the first time you'll be working with classes in this course, so be sure to check out the Python documentation
6+
# for how to declare a class and how to assign instance variables like `title`.
7+
8+
# Capitalization rules - we'll use the Chicago Manual of Style rules for this exercise
9+
# 1. Capitalize the first and last word
10+
# 2. Capitalize nouns, pronouns, adjectives, verbs, adverbs, and subordinate conjunctions (although, because)
11+
# 3. Lowercase articles (a, an, the), coordinating conjunctions (and, but, or), and prepositions
12+
# 4. Lowercase the `to` in an infinitive (Let's Learn to Play Chess)
13+
14+
15+
16+
import pytest
17+
18+
from books import Book
19+
20+
class TestBookClass():
21+
def test_can_create_book(self):
22+
book = Book("a")
23+
assert book is not None
24+
25+
def test_capitalize_first_letter(self):
26+
book = Book("homegoing")
27+
assert book.title == "Homegoing"
28+
29+
def test_capitalize_every_word(self):
30+
book = Book("animal farm")
31+
assert book.title == "Animal Farm"
32+
book = Book("true grit")
33+
assert book.title == "True Grit"
34+
35+
def test_no_article_capitalization(self):
36+
book = Book("to kill a mockingbird")
37+
assert book.title == "To Kill a Mockingbird"
38+
39+
def test_no_coordinating_conjunction_capitalization(self):
40+
book = Book("pride and prejudice")
41+
assert book.title == "Pride and Prejudice"
42+
43+
def test_no_article_capitalization_except_beginning_of_title(self):
44+
book = Book("the great gatsby")
45+
assert book.title == "The Great Gatsby"
46+
book = Book("the sound and the fury")
47+
assert book.title == "The Sound and the Fury"
48+
49+
def test_coordinating_conjunction_capitalized_as_first_word(self):
50+
book = Book("and then there were none")
51+
assert book.title == "And Then There Were None"
52+
53+
def test_no_preposition_capitalization(self):
54+
book = Book("love in the time of cholera")
55+
assert book.title == "Love in the Time of Cholera"
56+
book = Book("one flew over the cuckoo's nest")
57+
assert book.title == "One Flew over the Cuckoo's Nest"
58+
59+
def test_no_preposition_capitalization_except_beginning_of_title(self):
60+
book = Book("in cold blood")
61+
assert book.title == "In Cold Blood"
62+
book = Book("under the pendulum sun")
63+
assert book.title == "Under the Pendulum Sun"
64+
65+
def test_subordinate_conjunction_is_capitalized(self):
66+
book = Book("because it is bitter, and because it is my heart")
67+
assert book.title == "Because It Is Bitter, and Because It Is My Heart"
68+
69+
def test_always_capitalize_i(self):
70+
book = Book("everything i never told you")
71+
assert book.title == "Everything I Never Told You"
72+
73+
def test_can_handle_mixed_case_input(self):
74+
book = Book("hArRy PoTtEr AnD tHe PhIlOsOpHeR's StOnE")
75+
assert book.title == "Harry Potter and the Philosopher's Stone"

0 commit comments

Comments
 (0)