Python For Mbas Mattan Griffel Daniel Guetta instant download
Python For Mbas Mattan Griffel Daniel Guetta instant download
download
https://ebookbell.com/product/python-for-mbas-mattan-griffel-
daniel-guetta-23938726
https://ebookbell.com/product/python-for-mbas-mattan-griffel-daniel-
guetta-51904888
Python For Mbas Mattan Griffel Daniel Guetta Griffel Mattan Guetta
https://ebookbell.com/product/python-for-mbas-mattan-griffel-daniel-
guetta-griffel-mattan-guetta-169384686
https://ebookbell.com/product/python-for-programmers-oswald-
campesato-45333572
https://ebookbell.com/product/python-for-data-analysis-3rd-wes-
mckinney-46540276
Python For Engineers And Scientists Rakesh Nayak Nishu Gupta
https://ebookbell.com/product/python-for-engineers-and-scientists-
rakesh-nayak-nishu-gupta-46814830
https://ebookbell.com/product/python-for-engineers-and-scientists-
concepts-and-applications-rakesh-nayak-46844500
Python For Cybersecurity Using Python For Cyber Offense And Defense
Howard E Poston Iii
https://ebookbell.com/product/python-for-cybersecurity-using-python-
for-cyber-offense-and-defense-howard-e-poston-iii-46873132
Python For Probability Statistics And Machine Learning 3rd Edition 3rd
Edition Jos Unpingco
https://ebookbell.com/product/python-for-probability-statistics-and-
machine-learning-3rd-edition-3rd-edition-jos-unpingco-47165906
Python For Everyone 3rd Edition 3rd Cay S Horstmann Rance D Necaise
https://ebookbell.com/product/python-for-everyone-3rd-edition-3rd-cay-
s-horstmann-rance-d-necaise-47359588
PYTHON
for
MBA s
MATTAN GRIFFEL
and DANIEL GUETTA
PY THON FOR MBAs
PY THON
for
MBAs
INT RODUCTION 1
PART 1
PART 2
8 AGGREGATION 280
9 PRACTICE 302
9.3 New Product Analytics: Creating Fertile Ground for Success 303
9.4 The Next Frontier: Designing Dig’s Delivery-Specific Menu 306
9.5 Staffing for Success 313
9.6 Democratizing Data: The Summarized Order Dataset 316
9.7 Finding Fertile Ground for a New Delivery Service 320
9.8 Understanding Your Customers: Are Salad Eaters Healthier? 326
9.9 Orders and Weather 331
9.10 Wrapping Up 338
Notes 343
Index 347
PY THON FOR MBAs
INTRODUCTION
HELLO! We are Mattan Griffel and Daniel Guetta, and we’re going to teach you
about Python. Before we introduce ourselves, we want to tell you a little bit about
the intended audience for this book, what we’ll be learning together, and some
tips on how you can get the most out of reading this book.
This book is designed for people who have never coded before; so if you’re feel-
ing intimidated, don’t be. In fact, even if the only kind of Python you’ve heard of is
a snake, or if you’re not sure exactly what coding is, you’ll feel right at home—we’ll
discuss both in chapter 1. Businesspeople without a technical background decide
to start learning how to code for a lot of different reasons. Some want an intro-
duction to a different way of thinking—they realize the world runs on code, and
they don’t want to be left out. Some are looking for ways to write simple scripts to
streamline or automate their work. Others work with coders and technical teams
on a day-to-day basis and want to better understand what those teams do. Some
are tired of relying on overworked business intelligence teams to get answers from
their data and want to be more self-sufficient.
Whichever category you fall into—this book is for you. The material is based
on classes we have taught for a number of years at Columbia Business School to
professionals just like you. We are going to show you how to use Python to do all
kinds of useful things, like automating repetitive tasks to save yourself time and
money and performing data analyses to answer important business questions on
files far too large and complex to be handled in a spreadsheet.
Hopefully, you’ll find that this book provides valuable insight into what’s pos-
sible using technology and gives you a new skill that you can immediately use in
a business context.
2 INTRODUCTION
We have divided this book into two parts. In part 1, we will learn the basics of
Python (loops, variables, lists, and whatnot), and in part 2, we’ll dive into ways
Python can be used to analyze datasets in a real-world business context.
Unless you are already familiar with Python, you should begin by reading part 1
in order, from start to finish—resist the temptation to jump around. You will learn
the fundamental knowledge you need to do anything in Python. This part of the
book also contains a number of exercises, and we encourage you to spend some
time working on them. If you just read the book without trying these problems,
you’ll still learn something, but you may not remember it as well. The companion
website for this book contains digital versions of every piece of code, but for the
same reason, we recommend typing it in by hand rather than just copying and
pasting the code. If some questions pop into your mind like, “What happens when
I do X?” then try doing it! In the worst-case scenario, it doesn’t work. Then, you
can revisit what we were showing you. Either way, you’ll learn something new.
Part 2 is about using Python to analyze data in a business context. You should
begin by reading chapter 5, which introduces a different way to write code in
Python. This chapter also introduces the story of Dig, a restaurant chain based
in New York that we will return to again and again in this part of the book.
We have found that many Python books, even basic ones, seem to be written
for engineers—they focus on functionality rather than on how that functional-
ity might be used. By rooting part 2 in a real-life case study, we show you what
Python can do for you rather than teaching it in a vacuum. In the remaining
chapters, we discuss how Dig’s challenges can be addressed using data. We build
on the Python fundamentals you learned in part 1 to show you how to use massive
datasets to answer these questions.
Our aim is to teach you the basics of Python and to provide you with a map so
that you can decide what you want to learn more about on your own. As a result,
we’ll sometimes use informal terminology, and skip over some more technical
details. This is a deliberate choice on our part—it will prevent us from getting too
bogged down with details that aren’t essential and will help you get to applications
as quickly as possible. In our conclusion, we will point you to resources you can
use to take what you’ve learned to the next level, if you’re interested.
One of Python’s key strengths is the speed at which it evolves. Thousands of
developers around the world donate their time and energy to improve the lan-
guage and make it faster, richer, and more powerful. The speed at which Python
develops is so rapid that some features we cover in part 2 didn’t even exist when
we started writing it. We have created a companion website to this book (avail-
able at https://www.pythonformbas.com) to ensure that it stays up to date as the
INTRODUCTION 3
WELCOME TO PART 1. I’m Mattan Griffel and I’m going to teach you a little
bit about the basics of Python. I’m going to try to make it interesting and explain
some boring things in (hopefully) new and interesting ways. Let me first tell you
a little bit about myself.
I’m a two-time Y Combinator–backed entrepreneur. I previously started a
company called One Month, an online coding school that teaches people how to
code in just thirty days, and I’m currently the founder and chief operating officer
of Ophelia, a telemedicine company focused on helping people overcome opi-
oid addiction. I’m also an award-winning faculty member at Columbia Business
School, where I teach coding to MBA students and executives. Throughout my
career, I’ve taught tens of thousands of people how to code.
But I have a confession to make: I didn’t start off as a coder, and I never got a
degree in computer science. I began as in early-twenty-something in New York
City with an idea for a startup. I was working in marketing as my first job out of
college, and I’d spend my evenings dreaming about my startup idea, but I had a
problem: my idea required building software, and I didn’t know anyone person-
ally who could do that for me. I tried so hard to find a technical cofounder—
I went to hackathons and meetups and pitched people over drinks—but no luck.
Eventually, several of my friends grew tired of hearing me complain about how
hard it was to find a developer. One of them, John, confronted me over coffee:
“Either you have to learn how to code so that you can build this by yourself,”
he told me, “or I need you to stop talking about it because it’s getting annoying.”
6 PAR T I
The thought had never even crossed my mind. Why would I learn how to code?
Isn’t that what software engineers and people working in IT were for?
John shared a personal story with me. Years earlier, during a summer break in
high school, John was working as a parking garage attendant with a friend. When
they were bored, they often shared stories of what had happened the night before.
One of them had gone out with friends after drinking several Four Lokos and had
a pretty crazy night (Four Loko was a caffeinated alcohol drink that eventually
was banned in several states because it was downright dangerous). They joked for
a while about what it would be like if people could share stories about their Four
Loko–induced debauchery on a dedicated website.
John decided that while he was bored at his job that summer, he was going to
teach himself how to code. John picked up a few books and found some online
guides, and a few months later, fourlokostories.com was born. It became pretty
popular for a while—getting hundreds of thousands of pageviews and tens of
thousands of Facebook likes.
My friend John has since moved on to bigger and better projects. He’s actually
founded several other companies, many of which started with a random idea and
John spending a weekend writing some code. Hearing his story over coffee that
day, I was dumbstruck.
“You taught yourself how to code in one summer?” I asked John.
“Yeah, just don’t spend a lot of time on the basics,” he said. “Pick a project and
start working on it as soon as possible. And learn a newer language like Python
or Ruby.”
That conversation changed my life forever. I ended up quitting my job in
marketing and decided I’d try to learn how to code on my own. I didn’t have an
entire summer, though, so I gave myself one month to see how far I could get.
I started with a series of videos on the website Lynda.com, which I raced through
in about a week. Even though I didn’t really understand most of what I learned
at first, I kept going because it was exciting, and I enjoyed the feeling of building
something with my own two hands (even though it was all digital and I couldn’t
actually touch it).
Looking back on that period of my life, I remember being pretty frustrated at
times and then really excited when I finally got things to work. One day, I remember
doing something that broke all the code I had been writing, and I couldn’t get any
of it to run for two whole days. Then, when I finally fixed it, I had no idea how
I fixed it or how I had broken it in the first place. In retrospect, that’s a pretty
common experience, even for professional software engineers. You may even feel
that way as you read this book.
PAR T I 7
After spending some time learning how to code every day for about a month,
I had built the first version of my startup idea. It was embarrassing and it didn’t
work most of the time, but it was mine.
It’s hard to express how good it feels when you finally get your code to run.
I’ve always admired artists for their ability to see something inside their heads
(a painting, a sculpture, a story, or whatever) and then actually conjure it into
reality. For the first time in my life, through code, I felt like an artist.
Another confession: I’m still not a great coder—plenty of professional software
engineers can write better or faster code than me. But one thing I discovered
along the way is that I’m quite good at teaching coding to people who have never
done it before, and I enjoy it as well.
Most people think that because they never did well in math or science in high
school, that they’re never going to be able to learn how to code. That’s not true.
Learning to code is more like learning French or Spanish than it is like doing
math. Writing code can be a lot more fun and creative than you might expect.
People think coding is so hard because it tends to be taught really poorly. One
of the things I experienced while learning how to code was that most of the online
guides and books I found either went way too fast or way too slow. They started
by assuming I already had a lot of experience with code, or they started with the
basics and spent so much time on that material that I never got to do anything
useful with it and I got bored.
Instead, I hope that this book will be an entertaining and helpful guide to learn
how to code using Python. Let’s try to have some fun along the way.
1
GET TING STARTED
WITH PYTHON
By the end of this chapter, you’ll have a better understanding of Python, includ-
ing where it came from and what it can be used for. You’ll install Python and a
handful of other tools on your computer, and you’ll gain a basic understanding of
the command line, the place where we’ll begin running Python code. Finally, you
will run your first Python script and get some exposure to what coding in Python
is actually like.
Most experienced programmers only barely scratch the surface. A 2019 survey
by Stack Overflow found that almost 90 percent of programmers are self-taught,1
meaning that even professional programmers constantly come across new topics
and concepts they don’t know but have to figure out how to learn.
As an analogy, let’s consider a language like English. According to the Global
Language Monitor, the English language currently has 1,057,379.6 words.2 (Ever
stop to think about what a 0.6 word is? We, too. We still don’t know.) Yet the aver-
age fluent adult knows only twenty to thirty-five thousand words.3 Would you say
that the average language speaker isn’t “fluent” just because they don’t know all
the words? Probably not.
Learning a programming language like Python is pretty similar to learning a
language like English. Of course, it can be frustrating when you don’t quite know
the word you need to use to express an idea, or what code to write to solve a
particular problem. That’s what we’re here to help you with. Along the way, we’ll
also point out some common mistakes that beginner coders make, which should
protect you from doing anything too embarrassing.
Given the vast number of programming languages—C, Java, C++, PHP, JavaScript,
Python, Perl, Ruby, Visual Basic, Go—it’s hard to know where to start.
When most people start their journey learning how to code, the sheer number
of options to begin is overwhelming. It’s definitely enough to make someone feel
anxious, and many people tell us that they’re afraid of spending too much time
learning the wrong thing. Imagine taking six months to learn Python only to find
out that you should have been learning JavaScript instead.
Let us take a moment to calm your concerns. You’ll probably be all right no
matter where you start. A lot of what you’re learning when you first learn a pro-
gramming language isn’t specific to that language at all—it’s the basics of how
programming languages work in the first place. Most programming languages
share these building blocks. If you’ve never coded before, however, it can be hard
to understand why that is.
To help you understand what’s going on behind the “black box” of coding, we
start by taking you on a tour of how a programming language like Python could
be used to build something that we all probably use every day—a website.
In this book, we won’t be showing you how to build a website using Python—it’s
quite a complex topic that could take up a whole book on its own, and building
G E T T I N G STA R T E D W I T H P Y T H O N 11
websites doesn’t rank high on the list of what we’d expect an MBA to do with
Python. This is still a good way to introduce the topic of coding because it covers
many of the major areas of coding and because we interact with websites every day.
Most of the websites we visit are actually web applications. Applications are like
apps that you download on your phone or computer (think Microsoft Word or
Excel) except that with a web application, instead of downloading it, the application
sits on a server somewhere (in the “cloud”). You interact with a web application by
opening your browser and going to a website like facebook.com or twitter.com.
How are web applications built? Every web application has a front end and a
back end. The front end is the part that you see.
Different programming languages are used to write the front end and back
end. The front end of a web application is generally built using three program-
ming languages:
These three languages work together to make nearly every page on the web.
The HTML describes what’s on the page, CSS makes it look the way it does, and
12 PAR T I
JavaScript adds some of the flair and behavior of a page (things like popup notifi-
cations and live page updates).
That’s the front end, and there’s a lot more to be said, but that’s outside the scope
of this book. We’ll leave that to you to explore in greater depth if you’re interested.
For now, we’ll shift our focus to the part of a web application that most people
don’t see: the back end.
The back end is the metaphorical “black box” of coding. Think of it as the web
application’s “brain”; it carries out the bulk of the work, and then hands it over
to the front end so that it can be displayed to you as pretty web pages. For exam-
ple, if you search for a friend on facebook.com, the back end will look through
Facebook’s enormous database to find them, and then present it to the front end
so that it can be shown to you in your browser.
The back end usually consists of two things: a database and a set of rules.
The database stores all of the information that your web application needs
(e.g., usernames and passwords, photos, status updates, and everything else).
The rules in between a database and the webpages are what enable the web
application to figure out what information to get from the database and what to
do with it every time a user does something on the website. When it comes to
database languages, one is more popular than almost any other: SQL (commonly
pronounced “sequel” or “S-Q-L”). We won’t talk much about SQL, given that it’s
outside of the scope of this book.
Most programming languages you’ve heard of fit in between the database and
the web pages. Some that you might have heard of include Python, Ruby, PHP,
and Java. This is by no means an exhaustive list of languages, but it is where most
of the languages we have mentioned fit in.
They’re all basically the same, just a little different. We often are asked: “I’m
thinking of building X idea (a dog walking app, a better way to find roommates,
G E T T I N G STA R T E D W I T H P Y T H O N 13
a way to find cool events in your area, whatever). What programming language
should I learn?” Once you learn how programming languages actually work,
you’ll realize that this is kind of a funny question. It’s like saying, “I’ve got this
story I really want to tell, it’s a story of two star-crossed lovers. What language
should I use to tell it? English? French? Spanish?”
You probably can tell that story using any one of those languages, because that’s
what languages are for. Of course, the languages are all different. In some lan-
guages like French or Spanish, you’ve got masculine and feminine words. In other
languages like Chinese, you indicate past and future tense by putting a word at the
end of your sentence. Programming languages work the same way. You can do the
same things with most programming languages, although the code itself might
look a little different. Consider this example:
This figure shows three different snippets of code from three different lan-
guages: PHP, Python, and Ruby. You can easily spot some of the differences. The
word used is different in each case: echo, print, and puts. PHP uses semicolons
at the end of its sentences, but Python and Ruby don’t. Python uses parentheses,
whereas PHP and Ruby don’t need them. But when you run the code (we’ll talk
about what “running code” means in a bit), you get the same output.
14 PAR T I
All three lines of code print out Hello World. (This is, by the way, traditionally
the first lesson you learn when you’re learning a programming language—how to
print Hello World—and it’s always boring!)
What makes something a programming language? Python, and all the other
programming languages, are languages for humans to talk to computers.
Programming languages started off being very computer-friendly but not very
human-friendly. The following is an example of how you might tell a computer to
do something simple like print out “Winter is coming.” in binary code:
Binary is the lowest level at which instructions can be written for a computer.
It’s the most computer-friendly (it’s really fast), but it’s also the least human-
friendly (as you’ve noticed, it’s basically unreadable). Next, you can move up one
level, which is Assembly language:
section .text
global _start
_start:
mov edx,len
mov ecx,msg
G E T T I N G STA R T E D W I T H P Y T H O N 15
mov ebx,1
mov eax,4
int 0x80
mov eax,1
int 0x80
section .data
This version is only slightly more readable than the binary version. It includes
some familiar words, but it ends up being converted into binary anyway so that it
can be read by the computer. The following is an example of how you would write
the same thing in Java:
System.out.println("Winter is coming.");
Things are getting better now, and indeed, Java is a huge improvement over
Assembly when it comes to human readability. But we still don’t like the idea
of beginners learning to code with Java because there’s still so much overhead
to learn before you can do something as simple as print text. (For example, you
first have to learn the meaning of public, class, static, void, main.) And then
there’s Python:
print("Winter is coming.")
What a breath of fresh air. All of that in one simple line. Python has become
a popular programming language for beginners and experts alike because it
emphasizes human readability.
16 PAR T I
Forget Wall Street lingo. The language Citigroup Inc. wants its incoming
investment bank analysts to know is Python.
—Bloomberg, June 14, 2018
The programming language Python was named after Monty Python (the British
comedy group), not a snake (as many people think). It was created in 1991 by Guido
Van Rossum. He’s been known in the Python community as the “Benevolent
Dictator for Life” (BDFL).
Guido worked at Google from 2005 to 2012, where he spent half of his time
developing the Python language. Interestingly, much of the popularity of Python
comes from the fact that when Google was first conceived by Sergey Brin and
Larry Page at Stanford, they wrote their first web crawlers using Guido’s rela-
tively new Python.4 As Google started to grow, they made the smart business
move of hiring Guido. Google also spent a lot of resources building data science
tools in Python and released them for free to the open-source community. As a
result, many aspiring developers who wanted to learn Python from the best and
brightest were enticed to work at Google. This gave Google a competitive business
advantage in terms of hiring the most talented programmers.
We often are asked which big companies are using Python. The answer
is that most large companies and certainly almost every tech company uses
Python in some capacity. Examples include Google, Facebook, YouTube,
Spotify, Netflix, Dropbox, Yahoo, NASA, IBM, Instagram, and Reddit. The list
goes on and on. Python is so prevalent because it can be used for so many dif-
ferent things and is easy to use alongside other programming languages. For
example, even if a company’s main product isn’t built using Python, they may
use Python for machine learning, artificial intelligence (AI), or data analysis
behind the scenes.
As a result, Python is currently the fastest-growing major programming lan-
guage.5 According to Stack Overflow, an online community for developers, it’s
also considered to be the most wanted programming language.6
Companies like Citigroup and Goldman Sachs have begun training their
business analysts in Python. “Programming is going to be like writing was
when we were in school,” says Kimberly Johnson, the chief operating officer
G E T T I N G STA R T E D W I T H P Y T H O N 17
Before we can write and run Python code, we have to do a few things. This is what
we call setting up your “development environment.” It consists of three steps:
Although this process can be fast for some, others may run into problems
depending on how their particular computers are set up. We recommend allo-
cating about an hour to get everything set up properly, but you may not need this
much time.
Note that the software we use in this book should work on both Windows
computers and Mac computers (but unfortunately not on most cloud-based
laptops like Chromebooks, as of writing this). We’ve gone through some effort to
test it on both environments. When appropriate, we include screenshots for both
to ensure that no one feels left out.
You’ll need to install a text editor for writing code. We’ll be using a popular text
editor called Atom. For this book, it doesn’t really matter what text editor you use,
so if you have a preferred text editor, feel free to use that.
Even experienced developers sometimes run into problems and get frustrated
installing all the right tools on their computers. For example, when joining a new
company, it’s not uncommon for it to take several whole days to get all the software
installed properly. Our advice is to just stick with it if you’re running into problems,
18 PAR T I
The first time you open Atom, you may see a bunch of notifications and
announcements that you can close. Next, you’ll see a blank tab that should look
something like this:
This is where we’ll write our code, but we don’t need this for now, so feel free to
close down Atom for the time being.
Now it’s time to install Python. Actually, if you’re on a Mac, Python comes
preinstalled by default (but depending on when you got your computer, it’s
unlikely to be the most recent version). Windows doesn’t come with Python
by default.
G E T T I N G STA R T E D W I T H P Y T H O N 19
The command line is an application we can use to run Python code (among many
other things). We’re going to set up our command line so we can access it quickly
and know that it works.
macOS:
The Mac version of the command line is a program called Terminal that comes
with your computer. To find it:
1. Click on the magnifying glass in the top, right-hand corner of your screen (or
just hold the command key and hit the spacebar). A search bar should pop up.
2. Type “Terminal”.
3. Click on the Terminal application that looks like a black box. This should
open the Terminal.
4. Go to your dock on the bottom of your screen and right-click or Ctrl and
click on the Terminal icon to pull up a menu. Select Options > Keep in Dock.
Now that you have your Terminal open and it appears in your dock, you can
easily access it.
Windows:
On Windows, we’re going to use a program called Anaconda PowerShell Prompt
that comes included with the Anaconda installer:
1. Click Start.
2. Type “Anaconda Powershell Prompt”.
3. Click on the Anaconda Powershell Prompt application that looks like a
black box. This should open Anaconda Powershell Prompt. It will look like a
black window with white text. (Major warning: Windows comes with other
20 PAR T I
Now that you have your Anaconda PowerShell Prompt open and it appears in your
taskbar, you can easily access it.
If anything goes wrong during these steps, check out the Frequently Asked
Questions on our website at https://www.pythonformbas.com/install and you may
find a solution.
To ensure that you installed Python properly, open a new command line window
(Terminal or Anaconda PowerShell, depending on which you’re using), then type
python --version (that’s two hyphens, also called dashes), and hit enter:
Don’t worry if your command line doesn’t look exactly like ours.
Also, don’t worry if you don’t have the exact same version of Python. As long
as you see anything above Python 3.8, you should be able to run all of the Python
code in this book.
While you’re at it, type pip --version and hit Enter. As long as you see any
version number (and you don’t get an error message), you should be good to go.
G E T T I N G STA R T E D W I T H P Y T H O N 21
(base) mattan@Mattans-Macbook-Pro ~ %
This line tells you a few things. The first part (base) has to do with a feature of
the Anaconda installer—it’s possible to have different versions of Python installed
22 PAR T I
on your computer at the same time—but we won’t be using that feature here, so
again, you can safely ignore it.8
Then there’s mattan, which is our username on our computer. After that there’s
a @ and Mattans-Macbook-Pro which is the name of our computer. Then there’s
a space and a ~ (tilde), which actually tells you where you are on your computer
right now. That’s right, you’re somewhere on your computer when you open the
command line. We’ll get into that in a bit. Finally, there’s a %, another space, and
then a rectangle (the cursor).
So far, we’ve been showing the Mac version of the command line, but on a
Windows computer, you’ll see something like this instead:
(base) PS C:\Users\mattan>
The prompt starts with (base), which means the same thing as it did on a Mac.
Then you’ve got PS, which stands for PowerShell. After that you’ve got C:\Users\
mattan, which tells you where you are on your computer right now (we’ll explain
what that means in a moment), a >, a space, and then a blinking line (the cursor).
The area behind the blinking cursor indicates where you can type and is known
as the Prompt (as in, it’s prompting you to type stuff). At the prompt, you can
enter a command that you’ve memorized or looked up, hit Enter, and see the
output of your command.
For example, type the letters pwd and hit Enter. On a Mac, you should see some-
thing like this:
/Users/mattan
Path
------
C:\Users\mattan
What did we do with pwd, exactly? The command pwd stands for print work-
ing directory, and by running it, we’re commanding our computer to tell us what
folder we’re currently in.
G E T T I N G STA R T E D W I T H P Y T H O N 23
From now on, when we say to “run” a command, what we mean is open up the
command line, type a command into your prompt, and then hit Enter. Some-
times we’ll indicate this as follows:
% pwd
/Users/mattan
Here, the % is shorthand for the prompt (we’re cutting out all the other informa-
tion you see in your command line). This is pretty common when you’re looking
at code examples online. Whenever you see a % in front of some code, it means
you should type or copy and paste it into the command line (but don’t type the
% itself). Sometimes you won’t see a % and it will be up to you to figure out that
you’re supposed to run it in your command line—yes, this can be confusing when
you’re starting out, but it becomes intuitive over time.
Go ahead and run pwd three times and each time say “print working directory”
out loud. This will help you remember it.
We keep saying that you’re somewhere on your computer when you open up the
command line. What do we mean by that? Well, if you’re on a Mac, try running
the following command (remember not to actually type the % part):
% open .
% start .
memorize each new term. When there’s an important term for you to remember,
we’ll let you know.)
Now try running ls and see if you can figure out what it’s doing.
Here’s what we get:
% ls
Applications
Movies
Music
Desktop
Documents
Pictures
Downloads
Public
anaconda3
Library
Windows users will see a bunch more information as well, including last write
time and length. You can safely ignore all of that information if it seems confusing
to you. If you compare it with the window that opened when you ran open . (on
a Mac) or start . (on a Windows), you’ll notice that you see the same folders as
you do in the output from the command line:
G E T T I N G STA R T E D W I T H P Y T H O N 25
The command ls stands for list and it basically means “tell me what folders
and files are in the folder that I’m currently in.”
The last command you need to know about is cd, which stands for change
directory. cd lets you move from your current folder to another folder like this:
% cd Desktop
You won’t get any output from running this command, but you can check that
it worked by running pwd:
% pwd
/Users/mattan/Desktop
cd lets you move into any of the folders inside the folder you’re currently in.
(Technically, cd is the command and the thing that comes after the space, the
folder name, is called an argument.)
If you want to move into a folder whose name has spaces in it, you’ll need to put
the folder name in quotes. For example:
% cd "Work Documents"
Because the command line interprets each space as a new argument, it doesn’t
know that you want it to be the name of one folder. In practice, developers will
often just use _ (underscores) instead of spaces in folders and file names to avoid
confusions like this.
If you find yourself inside of a folder that doesn’t have any other folders in it,
and you want to go back, you can run the following:
% cd ..
The .. stands for the folder one level up from the folder you’re currently in
(sometimes called the parent folder or the enclosing folder). So basically what
you’re doing with cd .. is saying “take me back a level.”
Now that you know pwd, ls, and cd, you have the three commands you need
to move around your computer in the command line. There are hundreds of other
26 PAR T I
commands out there, but these are the only three you need to know right now to
run Python code.
Take a few minutes to practice them now. Try choosing a random folder some-
where on your computer, open up the command line, and see if you can figure out
how to get to it. If you get lost at any point, you can run:
% cd ~
cd with a ~ (tilde) as an argument will always take you back to your home direc-
tory (where you start when you first open up the command line). In the worst-
case scenario, you can always quit the command line and open it up again. Then,
you should be back where you started.
It is not particularly important, but the clear command lets you clear out any
previous commands you’ve run.
% clear
This is helpful if you don’t like the clutter of seeing a bunch of text every time
you use the command line.
Now that we’ve learned a few basic commands, let’s create a new folder on your
desktop where you can save the code that we write as we move through this book.
We recommend putting it on your desktop so that it’s easy to see and get back to,
but you can also create this new folder anywhere you want as, long as you know
how to get back to it again later.
Make sure you’re in your home directory by opening up a new command line
window or running cd ~:
% cd ~
% pwd
/Users/mattan
G E T T I N G STA R T E D W I T H P Y T H O N 27
% cd Desktop
% pwd
/Users/mattan/Desktop
% mkdir code
Check your desktop. You should see a new empty folder named code. We
didn’t teach you the mkdir command earlier because it’s probably easier to just
right click somewhere on your desktop and select New Folder, but we’re showing
it to you just now because it’s fun.
Even though you just created a new folder in the command line, you’re not
inside of it yet. You still need to cd into it:
% cd code
% pwd
/Users/mattan/Desktop/code
You did it. Now close down your command line, open up a new one, and nav-
igate to your new folder. To get some practice, repeat this task three more times.
Now that we’ve explored the command line, let’s step away from it for a second
to run our first bit of Python code. (It’s okay if the words “run Python code” don’t
mean anything to you at the moment. Just go with it for now, and it will start to
make more sense soon.)
We’ve provided a file at https://www.pythonformbas.com/code named happy
_hour.py (go there now and download this file). In Python, a file with code that you
can run is sometimes called a script. Don’t worry about what’s inside the file for now.
First things first, move it into your newly created code folder on your desktop.
That way you can easily find it later. Then open up a new command line window.
Navigate to your code folder using the cd command. (Remember how to do this
28 PAR T I
from the previous section on the command line? If not, go back and review it.) At
this point, check to make sure you’re in the right folder by running pwd and ls.
% pwd
/Users/mattan/Desktop/code
% ls
happy_hour.py
You should see the happy_hour.py file that you’ve put into your code folder.
Make sure you see it when you run ls; otherwise, this next step won’t work. If you
don’t see it, you either (a) didn’t move the file into the right folder, or (b) didn’t
navigate into that folder in the command line.
Now that you have taken care of that, run the file in the command line by typ-
ing python happy_hour.py and hitting enter:
% python happy_hour.py
directory.
If you got that error, it means that it can’t find the file you’re trying to run.
Either you’re in the wrong folder, or the file that you thought you moved isn’t
actually there. Go back and make sure the file is where you think it is (in the code
folder on your desktop).
Another error you might have gotten looks something like this:
% python
>>> happy_hour.py
G E T T I N G STA R T E D W I T H P Y T H O N 29
The error you see here is interesting but slightly more complicated to explain.
If you typed in just the word python and hit Enter without adding a space
and putting happy_hour.py at the end, you accidentally opened up something
called Interactive Mode. We’ll return to this in a second, but for now, just exit
out of it by typing either exit() and hitting Enter, or pressing Ctrl and
D on a Mac or Ctrl and Z on Windows. You should be back at the command
line prompt.
But let’s say you did manage to get the file to run. Even so, you probably didn’t
see the same output that we had in our example. Try running it again a few times
and see what you get (note that if you press the up arrow, the last piece of code
you ran will be displayed in the terminal—no need to retype it multiple times).
% python happy_hour.py
% python happy_hour.py
% python happy_hour.py
How about you go to The Back Room with that person you forgot to
text back?
Notice the output is different each time. What do you think is happening?
Before we tell you, we want you to try something. Open up happy_hour.py
in your text editor (Atom) and read the code on your own. You can do this in
two ways:
1. Open Atom, go to File > Open . . . , find the file and click Open.
2. Right click on happy_hour.py, select Open With, and find Atom in the list
of applications.
C H A N G I N G YO U R D E FA U LT T E X T E D I TO R F O R . P Y F I L E S
To change your default text editor for .py files on a Mac, right click on any file with
a .py extension and select Get Info. Under Open With find Atom and then click the
Change All . . . button to apply the change to all .py files.
On a Windows, go to Start Menu, search for “default apps” and click on it, scroll
down the window and click on “Choose default apps by file type,” scroll down to
.py and choose Atom as the default.
These instructions may change with operating system updates, so you may have
to do some Googling to get this to work.
import random
"PDT"]
people = ["Mattan",
"Sarah",
"Samule L. Jackson"]
random_bar = random.choice(bars)
random_person = random.choice(people)
This is Python code. Don’t worry about the fact that we haven’t taught you
anything about Python or code yet. Just take a minute of two to read through this
code, line by line, and see if you can figure out what’s going on at a high level.
Even if it looks like gibberish, don’t let your eyes gloss over it. Study it and start
to ask what each part might be doing. Do you see patterns or repetitions? Look
for clues, even if none of it makes sense to you yet.
Ready, go!
G E T T I N G STA R T E D W I T H P Y T H O N 31
Hopefully, you’ve read through the code on your own. If not, please take a sec-
ond to do that now. Part of the skill of coding is being able to read other people’s
code that you haven’t seen and figure out why it’s doing what it’s doing. So, we
need to start working out that muscle now.
Here’s how we would read the file. We would break the file down into three parts:
1. Top
2. Middle
3. Bottom
import random
"PDT"]
people = ["Mattan",
"Sarah",
"Samule L. Jackson"]
First, note we have some sort of import random line of code. We don’t yet
know what it does.
Then, it seems like two lists are being created: bars and people. We might not
understand the exact characters yet (why are there square brackets [] and quota-
tion marks ""?), but we get the general idea.
The middle section of code seems to be doing some of the work:
random_bar = random.choice(bars)
random_person = random.choice(people)
Our guess (okay, we know, but let’s pretend we all are seeing this for the first
time) is that this code is choosing a random bar and a random person from the
list of bars and people. Remember that import random that we saw earlier? Per-
haps that has something to do with the random.choice we’ve got here.
32 PAR T I
Finally, the bottom section looks like what we see in the command line:
1. Oops, we spelled Samuel L. Jackson’s name wrong. Can you fix it for us?
2. Add one friend to the list. Did you get an error?
3. Have it print out two random people instead of just one.
Take a few minutes to do this, but not more than five or so.
If you get stuck, keep at it for a bit, but don’t get too frustrated if you ultimately can’t
figure it out. The point of these challenges is to test the limits of what you currently
know how to do, so that your mind expands a bit and you hopefully learn something
new. The point is not to get so frustrated that you give up. Be kind to yourself.
Did you figure it out? The first part of the challenge should have been pretty
easy. Just move around the l and the e in this line (line 11):
"Samule L. Jackson"]
G E T T I N G STA R T E D W I T H P Y T H O N 33
So that it reads:
"Samuel L. Jackson"]
people = ["Mattan",
"Sarah",
"Samuel L. Jackson",
"Daniel"]
people = ["Mattan",
"Sarah",
"Samuel L. Jackson"
"Daniel"]
Do you see the difference? It’s subtle. The second example is missing a comma
at the end of the second-to-last line:
"Samuel L. Jackson"
% python happy_hour.py
How about you go to Death & Company with that person you forgot to
text back?
% python happy_hour.py
Do you see what happened when we ran the file that second time? It smushed
together Samuel L. Jackson and Daniel so what we got was Samuel L.
JacksonDaniel.
Why this happens is something that will make more sense once we get to strings
and the print() function. For now, it’s enough to know that without the comma,
it just doesn’t work correctly.
When it comes to programming, one thing that often trips up beginners is the
fact that a little thing like a missing comma can make your code not work, or at
least not work correctly.
When it comes to code, computers can’t interpret text in the same way that a
human can. A human can see a bit of text with a comma missing and assume that
you meant to put a comma there. They’ll understand what you meant to write.
A computer, in contrast, makes no assumptions about what you meant. If you
don’t put it in the code, the computer won’t do it. This is a good thing because it
means your computer won’t ever do things you didn’t tell it to do (you know what
they say about assumptions), but it’s annoying because it means you have to be
pedantic about everything.
G E T T I N G STA R T E D W I T H P Y T H O N 35
Our favorite illustration of this in English is the sentence “Let’s eat Grandma!”
which means something quite different than the phrase “Let’s eat, Grandma!”
Remember: punctuation saves lives.
If that idea scares you because you’re not a detail-oriented person, that’s okay.
It takes a bit of getting used to, but eventually your eye will start to notice the
small stuff naturally without you having to think much about it.
Back to the final challenge, which was to change the code so that it prints out
two random names instead of just one.
This was by far the trickiest part of the challenge, so if you didn’t figure it out,
that’s okay.
The key is to look at this line:
random_person = random.choice(people)
Did you guess that if you include another line just like it, then you can grab
another random person from your list of people? Like this:
random_person2 = random.choice(people)
You also might have created a second list of people, but that isn’t necessary in
this case. You can pull from the same list.
The only other change you’d need to make to actually see the output would be
to change the final print line:
{random_person2}?")
Note that our line of code is already starting to get long. This may be a good
point to mention that in Python, line breaks matter. The previous line of code,
while it’s printed in this book as being two lines, needs to be all on one line of
code otherwise Python won’t be able to run it. We’ll come back to this topic later.
Where possible, we’ve tried to break down long lines of Python code into shorter
ones so that they can be printed in this book the same way they should be typed.
36 PAR T I
In some cases though, that isn’t really possible due to limitations in the number of
characters that can be printed on one line in this book.
Back to our file, let’s run the updated code a few times:
% python happy_hour.py
How about you go to McSorley's Old Ale House with Mattan and Daniel?
% python happy_hour.py
How about you go to The Back Room with Samuel L. Jackson and Sarah?
At this point, you might be happy, but if you kept running the code, you might
eventually realize a problem:
% python happy_hour.py
How about you go to McSorley's Old Ale House with Daniel and Daniel?
Every once in a while, the two randomly selected people will be the same per-
son. In computer programming, this type of error is sometimes called a bug or an
edge case. An edge case occurs when your code works normally most of the time,
but occasionally it does something wrong.
You might want us to tell you how to fix it. But this time, we’ll flip the question
around and ask you: How would you fix it?
Take a second and think at least conceptually about how you might get around
a problem like this. We may not know enough about Python to fix this problem
yet, but it’s something we’ll be able to come back to soon.
We have a final challenge for you. Your challenge is to take 10 minutes or so and
create your own randomizer script (remember, a script is just a file with Python
code inside of it that you can run).
There are many ideas for randomizer scripts available on the web, and some of
them are quite popular. For inspiration, the next two examples feature two of our
favorites (we apologize in advance for the crude language):
G E T T I N G STA R T E D W I T H P Y T H O N 37
1.6 WRAPPING UP
WE’VE LEARNED what it means to “run” Python code, but we don’t yet have
a grasp of the basic building blocks of a Python script. In this chapter, we’ll start
learning the basics of what we can do with Python.
By the end of this chapter, you’ll be able to create a basic Python script that takes
input from a user, do some work to it, and then get back an output. You’ll also
learn about two different ways of running Python code, how to use the print()
function, how to read and troubleshoot Python errors, comments and variables,
some of the Python data types (e.g., floats, integers, and strings), and how to get
user input.
There are two ways of running Python code. The first, which we’ve already seen,
is to run a script in the command line like this:
% python script.py
Other documents randomly have
different content
2d. It was nearer the principal routes of travel, hence more easily
accessible.
3d. One can visit it on wheels.
4th. Last, and best for the tired tourist, an excellent hotel at the very
margin of the grove; Sperry & Perry, proprietors.
The grove extends northeast and southwest about five eighths of a
mile. Its width is only about one fifth as great. It stands in a shallow
valley between two gentle slopes. Its height above the sea is four
thousand seven hundred and fifty-nine feet. In late spring or early
winter a small brook winds and bubbles through the grove; but
under the glare of summer suns and the gaze of thronging visitors, it
modestly "dries up."
The grove contains about ninety trees which can be called really
"big," besides a considerable number of smaller ones deferentially
grouped around the outskirts. Several of the larger ones have fallen
since the grove was discovered, in the spring of 1852; one has had
the bark stripped off to the height of one hundred and sixteen feet,
and one has been cut down, or, rather, bored and sawed down. The
bark thus removed was exhibited in different cities in this country,
and finally deposited in the Sydenham Crystal Palace, England, only
to be burned in the fire which destroyed a part of that building some
years since. The two trees thus destroyed were among the finest, if
not the very finest in the grove. Among those now standing, the
tallest is the "Keystone State;" the largest and finest, the "Empire
State."
The following table gives the height of all the trees measured by the
State Survey, and their girth six feet from the ground:
Names of Trees. Girth. Height.
Keystone State 45 325
General Jackson 40 319
Mother of the Forest (without bark) 61 315
Daniel Webster 47 307
Richard Cobden 41 284
Starr King 52 283
Pride of the Forest 48 282
Henry Clay 47 280
Bay State 46 275
Jas. King of William 51 274
Sentinel 49 272
Dr. Kane 50 271
Arbor Vitae Queen 30 269
Abraham Lincoln 44 268
Maid of Honor 27 266
Old Vermont 40 265
Uncle Sam 43 265
Mother (and Son) 51 261
Three Graces (highest) 30 262
Wm. Cullen Bryant 48 262
U. S. Grant 34 261
Gen. Scott 43 258
Geo. Washington 51 256
Henry Ward Beecher 34 252
California 33 250
Uncle Tom's Cabin 50 250
Beauty of the Forest 39 249
J. B. McPherson 31 246
Florence Nightingale 37 246
James Wadsworth 27 239
Elihu Burritt 31 231
The exact measurement of the diameter and the ascertaining of the
age of one of the largest trees in this grove, was accomplished by
cutting it down. This was done soon after the discovery of the grove.
It occupied five men during twenty-two days. They did it by boring
into the tree with pump augers. The tree stood so perfectly vertical
that, even after they had bored it completely off, it would not fall. It
took three days' labor driving huge wedges in upon one side until
the monumental monster leaned, toppled and fell.
They hewed and smoothed off the stump six feet above the ground,
and then made careful measurements as follows:
Across its longest diameter, north of centre, 10 feet 4 inches.
Across its longest diameter, south of centre, 13 feet 9½ inches.
Total largest diameter, 24 feet 1½ inc's.
The shorter diameter, from east to west, was twenty-three feet,
divided exactly even, eleven and one half feet from the centre each
way.
The thickness of the bark averaged eighteen inches. This would add
three feet to the diameter, making the total diameter as the tree
originally stood, a little over twenty-seven feet one way, and twenty-
six feet the other. That is eighty-five feet in circumference, six feet
from the ground.
The age was ascertained thus: After it had been felled, it was again
cut through about thirty feet from the first cut. At the upper end of
this section, which was, of course, nearly forty feet above the
ground, as the tree originally stood, they carefully counted the rings
of annual growth, at the same time exactly measuring the width of
each set of one hundred rings, counting from the outside inwards.
These were the figures:
First hundred rings 3.0inches.
Second hundred rings 3 "
Third hundred rings 4 "
Fourth hundred rings 3 "
Fifth hundred rings 4 "
Sixth hundred rings 4 "
Seventh hundred rings 4 "
Eighth hundred rings 5 "
Ninth hundred rings 7 "
Tenth hundred rings 7 "
Eleventh hundred rings 10 "
Twelfth hundred rings 13 "
Fifty-five years 9.4 "
1,255 years. 80.8 inches.
A small hole in the middle of the tree prevented the exact
determining of the number of rings which had rotted away, or were
missing from the centre; but allowing for that, as well as for the time
which the tree must have taken to grow to the height at which they
made the count, it is probably speaking within bounds, to say that
this tree was, in round numbers, thirteen hundred years old!
As the table shows, this grove contains four trees over three
hundred feet high. The heights of these big trees, in both the great
groves, are usually overstated. The above measurements were
carefully and scientifically made—in several cases repeated and
verified—and may be relied on as correct.
The "Keystone State" enjoys the proud honor of lifting its head
higher than any other tree now known to be standing on the
western continent. Australia has trees a hundred and fifty feet
higher. The stories occasionally told of trees over four hundred feet
high having once stood in this grove, have no reasonable foundation
and are not entitled to belief. Neither is it true, as some have
marvelously asserted, that it takes two men and a boy, working half
a day each, to look to the top of the highest tree in this grove.
The Calaveras trees, as a rule, are taller and slimmer than those of
Mariposa. This has probably resulted from their growing in a spot
more sheltered from the high winds which sweep across the Sierra,
to which other groves have been more exposed.
The Mariposa Grove,
likewise named from the county in which it stands, is about sixteen
miles directly south of the lower hotel in Yosemite valley, and about
four miles southeast of Clark's Ranch. Like the Calaveras Grove, it
occupies a shallow valley or depression in the back of a ridge which
runs easterly between Big Creek and the South Merced. One branch
of the creek rises in the grove.
The grant made by Congress is two miles square and embraces two
distinct groves; that is, two collections of big trees, separated by a
considerable space having none. The upper grove contains three
hundred and sixty-five trees of the true Sequoia Gigantea species,
having a diameter of one foot or over. Besides these, are a great
number of younger and smaller ones.
The lower grove is not as large, and its trees are more scattered. It
lies southwesterly from the upper. Some of its trees grow quite high
up the gulches on the south side of the ridge which separates the
two groves.
On Wednesday, July 7th, 1869, the largest trees of this grove were
carefully measured, under the guidance and with the assistance of
Mr. Clarke himself, one of the State Commissioners charged with the
care of these groves and of the Yosemite valley. To prevent
misunderstanding and insure uniformity, each tree was measured
three feet from the ground, except where the outside of the base
was burned away, when the tree was girted seven and a half feet
above ground.
The following figures are taken from that day's phonographic
journal, written on the spot:
The "Grizzly Giant," seven and one half feet up, measures seventy-
eight and one half feet in circumference. Three feet above ground
this tree measured over a hundred feet round; but several feet of
this measurement came from projecting roots, where they swell out
from the trunk into the mammoth diagonal braces or shores,
necessary to support and stiffen such a gigantic structure in its hold
upon the earth.
One hundred feet up, an immense branch, over six feet through,
grows out horizontally some twenty feet, then turns like an elbow
and goes up forty feet. It naturally suggests some huge gladiator,
uncovering his biceps and drawing up his arm to "show his muscle."
This is the largest tree now standing in the grove, and is the one of
which Starr King wrote:
"I confess that my own feeling, as I first scanned it, and let the eye
roam up its tawny pillar, was of intense disappointment. But then, I
said to myself, this is, doubtless, one of the striplings of this Anak
brood—only a small affair of some forty feet in girth. I took out the
measuring line, fastened it on the trunk with a knife, and walked
around, unwinding as I went. The line was seventy-five feet long. I
came to the end before completing the circuit. Nine feet more were
needed. I had dismounted before a structure eighty-four feet in
circumference, and nearly three hundred feet high, and I should not
have guessed that it would measure more than fifteen feet through."
Here, as in Yosemite and at Niagara, tourists are usually
disappointed in the first view. The lifelong familiarity with lesser
magnitudes makes it almost impossible for the mind to free itself
from the trammels of habit, and leap at a single bound, into any
adequate perception of the incredible magnitudes which confront
him. One needs spend at least a week among these Brobdignagian
bulks, come twice a day and stay twelve hours each time, before he
grows to any worthy appreciation of their unbelievable bigness.
Of the other trees, the largest ten, measured three feet above
ground, gave the following circumferences:
La Fayette 83 feet.
The Governor 75 "
Chas. Crocker 75 "
The Chief Commissioner 74 "
Governor Stanford 74 "
Washington 72 "
Pluto's Chimney 71 "
The Big Diamond (Koh-i-noor) 65 "
The Governor's Wife 62 "
The Forest Queen 58 "
Others of equal size, possibly greater than some above, were not
measured.
"The Governor" is a generic name, applied in honor of him who may
happen to be the actual incumbent at any time. At present, of
course, it means Gov. Haight. It is an actual botanical fact, that the
tree has actually gained in height under the present gubernatorial
administration. It certainly is not as low(e) by several inches as
during the reign, or lack of rain, of the preceding incumbent.
The same general complimentary intention christened the
"Governor's Wife," which has as graceful a form and as dignified a
bearing among trees as such a lady should have among the women
of the State. Then, too, the tree stands with a gentle inclination
toward "The Governor," which may not be without its suggestions to
those fond of tracing analogies.
The "Chief Commissioner" is the largest of a clump of eight, which
stand grouped, as if in consultation, at a respectful distance from the
Governor.
"Pluto's Chimney" is a huge old stump, burned and blackened all
over, inside and out. Hibernian visitors sometimes call it "The Devil's
Dhudeen." It is between forty and fifty feet high. On one side of the
base is a huge opening, much like a Puritan fireplace or a Scotch
inglenook; while within, the whole tree is burned away so that one
can look up and out clear to the very sky through its huge circular
chimney. Outside, the bark and the roots have been burned wholly
away. Before the burning, this tree must have equaled the largest.
Nearly in front of the cabin in the upper grove, and not far from the
delicious spring before alluded to, stands a solitary tree having its
roots burned away on one side, leaning south, and presenting a
general appearance of trying to "swing round the circle." In view of
all these facts, some imaginative genius once christened it "Andy
Johnson." The only inappropriate thing in the application of that
name was the fact that the tree stood so near a spring of cold water.
The "Big Diamond" or "Koh-i-noor" is the largest of a group of four
very straight and symmetrical trees occupying the corners of a
regular rhombus or lozenge, so exactly drawn as to readily suggest
the name "Diamond Group," by which they have been called.
As already remarked, the Mariposa Grove really consists of two
groves—the upper and the lower, which approach within a half mile
of each other. The upper grove contains three hundred and sixty-five
trees; one for every day in the year, with large ones for Sundays. By
an unfortunate omission, however, it makes no provision for leap
year. This is the principal objection which unmarried spinster tourists
have thus far been able to urge against it.
The lower grove has two hundred and forty-one trees, generally
smaller than those of the upper grove. The total number in both
groves, according to the latest official count, is six hundred and six.
Within ten years several trees have fallen, and others follow them
from time to time, so that the most accurate count of them made in
any one year might not tally with another equally careful count a
year earlier or later.
Among the prostrate trees lies the "Fallen Giant," measuring eighty-
five feet around, three feet from the present base. The bark, the
sapwood, the roots, and probably the original base, are all burned
away. When standing, this monster must have been by far the
largest in both groves, and, indeed, larger than any now known in
the world. It should have been called "Lucifer," a name hereby
respectfully submitted for the consideration of future tourists.
The living trees of this species exude a dark-colored substance,
looking like gum, but readily dissolving in water. This has a very
acrid, bitter taste, which probably aids in preserving the tree from
injurious insects, and preventing the decay of the woody fibre.
The fruit or seed is hardly conical, but rather ellipsoidal or rudely
oval in form, an inch and a half long by one inch through, and
looking far too insignificant to contain the actual germ of the most
gigantic structure known to botanical science.
Their age, indicated by the concentric rings of annual growth,
carefully counted and registered by the gentlemen of the State
Survey, varies from five to thirteen, possibly fifteen, centuries.
The word "Sequoia," is the Latin form of the Indian Sequoyah, the
name of a Cherokee Indian of mixed blood, who is supposed to have
been born about 1770, and who lived in Will's Valley, in the extreme
northeastern corner of Alabama, among the Cherokees. His English
name was George Guess. He became famous by his invention of an
alphabet, and written letters for his tribe. This alphabet was
constructed with wonderful ingenuity. It consisted of eighty-six
characters, each representing a syllable, and it had already come
into considerable use before the whites heard anything of it. After a
while, the missionaries took up Sequoyah's idea, had types cast,
supplied a printing press to the Cherokee nation, and in 1828 started
a newspaper printed partly with these types. Driven, with the rest of
his tribe, beyond the Mississippi, he died in New Mexico, in 1843. His
alphabet is still in use, though destined to pass away with his
doomed race, but not into complete oblivion, for his name, attached
to one of the grandest productions of the vegetable kingdom will
keep his memory forever green.
For the foregoing bit of aboriginal biography, we gratefully
acknowledge our obligation to Prof. Brewer and the gentlemen of
the State Survey, to whom he originally furnished it.
Had Sequoyah's name been Cadmus—had the Cherokees been
Phenicians—and had this modern heathen of the eighteenth century
invented his alphabet away back before the Christian era, his name
would have stood in every school history among those of inventors,
philosophers, discoverers and benefactors; as it is he's "only an
Indian." No one can deny, however, that he was one of the best
re(a)d men in the history of the world.
Both the Calaveras and the Mariposa groves contain hollow trunks of
fallen trees, through which, or into which, two and even three
horsemen can ride abreast for sixty or seventy feet. Each grove,
also, has trees which have been burned out at the base, but have
not fallen. Still standing, they contain or enclose huge charcoal-lined
rooms, into which one can ride. The writer has been one of four
mounted men who rode their horses into such a cavity in the
Mariposa grove, and reined their horses up side by side without
crowding each other or pressing the outside one against the wall.
One who has seen only the ordinary big trees of "down east," or
"out west," forests, finds it hard to believe that any such vegetable
monsters can really exist. Even the multiplied and repeated
assurances of friends who have actually "seen them, sir," and
"measured them myself, I tell you," hardly arrest the outward
expression of incredulity, and seldom win the inward faith of the
skeptical hearer. Fancy yourself sitting down to an after-dinner chat
in the fifteen-foot sitting room, adjoining the dining room of equal
size. You fall to talking of the "Big Trees." You say, "Why, my dear sir,
I have actually rode into, and sat upon my horse in, a tree whose
hollow was so big that you could put both these rooms into it, side
by side, and still have seven or eight feet of solid wood standing on
each side of me. No, sir, not romancing at all. It's an actual,
scientific, measured fact, sir." Your friend looks quizzically and
incredulously into both your eyes, as he says, "Why, now see here,
my dear fellow, do you suppose I'm going to believe that? Tell a
moderate whopper, and back it up with such repeated assertion and
scientific authority, and you might possibly make me believe it, or at
least, allow it until you were fairly out of hearing; but to sit here at a
man's own fireside and tell him such a monstrous story as that, and
expect him to swallow it for truth—ah, no, my dear fellow, that's too
much, altogether too much."
So you have to give it over and drop the argument for the present,
in the hope that some one of the numerous excursion parties, now
so rapidly multiplying every year, will soon include him, carry him
into the actual presence of these veritable monsters of the vegetable
kingdom, confront him with their colossal columns, and compel his
belief.
And yet the general incredulity is hardly to be wondered at, after all.
In nearly every one of us, our faith in what may be, largely depends
upon our personal knowledge of the facts which have been. In
matters pertaining to the outward, the material, the physical world,
our actual experience of the past governs our belief as to the future.
And even when the objects of our disbelief are set bodily before our
vision, and we have actually seen them and handled them, it is often
difficult to believe our own eyes. So far is "seeing from believing"
when the sight so far surpasses all former experience.
There is another grove of big trees in Fresno county, about fourteen
miles southeast of Clark's. It is not far from a conspicuous point
called Wammelo Rock. The State Survey did not include it, neither
have tourists usually visited it. According to the description of Mr.
Clark, who has partially explored it, it extends for more than two
miles and a half in length, by from one to two in width. He has
counted five hundred trees in it, and believes it to contain not far
from six hundred in all. The largest which he measured had a
circumference of eighty-one feet at three feet from the ground.
Following along the slope of the Sierras, to the southeast about fifty
miles, between King's and Kaweah rivers, we find the largest grove
of these trees yet discovered in the State.
The State Survey partially explored this locality, and have given us
the following particulars: The trees form a belt rather than a grove.
This belt is found about thirty miles north-northeast of Visalia, near
the tributaries of the King's and Kaweah rivers, and along the divide
between. They are scattered up and down the slopes and along the
valleys, but reach their greatest size in the shallow basins where the
soil is more moist.
Along the trail from Visalia to Big Meadows the belt is four or five
miles wide and extends through a vertical range of twenty-five
hundred feet; that is, the trees along the lower edge of the belt
stand nearly half a mile in perpendicular height below those along its
upper boundary. The length of this belt is as much as eight or ten
miles and may be more.
These trees are not collected in groves, but straggle along through
the forests in company with the other species usually found at this
height in the Sierras. They are most abundant between six and
seven thousand feet above the sea. Their number is very great;
probably thousands might be counted. In size, however, they are not
remarkable; that is, in comparison with those of Calaveras and
Mariposa. But few exceed twenty feet in diameter—the average is
from ten to twelve feet, while the great majority are smaller.
One tree which had been felled, had a diameter of eight feet, not
including the bark, and was three hundred and seventy-seven years
old. The largest one seen was near Thomas' Mill. This had a
circumference of one hundred and six feet near the ground, though
quite a portion of the base had been burned away.
Another tree, which had fallen and been burned hollow, was so large
that three horsemen could ride abreast into the cavity for thirty feet,
its inside height and width being nearly twelve feet. Seventy feet in,
the diameter of the cavity was still as much as eight feet.
The base of this tree could not be easily measured; but the trunk
was burned off at one hundred and twenty feet from the base, and
at that point had a diameter, not including the bark, of thirteen feet
and two inches. At one hundred and sixty-nine feet from its base,
this tree was still nine feet through. The Indians speak of a still
larger tree to the north of King's river. It was not in the power of the
State Survey to look it up and measure it at that time.
All through these forests young Big Trees of all sizes, from the
seedling upwards, were very numerous. At Thomas' Mill they cut
them up into lumber, as if they were the most common tree in the
forest.
Fallen trunks of old trees are also numerous. Many of these must
have lain for ages, as they had almost wholly rotted away, though
the wood is very durable.
Judging from the number of these trees found between King's and
Kaweah rivers, it would seem that the Big Trees best like that locality
and its vicinity, so that it is not improbable that a further exploration
would show a continuous belt of some fifty or sixty miles in extent.
From the researches thus far made, it appears that the Big Tree is
not as strange and exceptional as most suppose. It occurs in such
abundance, of all ages and sizes, that there is no reason to conclude
that it is dying out, or that it belongs exclusively to some past
geological or botanical epoch. The age of the big trees is not as
great as that assigned by some of the highest authorities to some of
the English yews. And in height they hardly begin to equal that of
the Australian Eucalyptus amygdalina, many of which, on the
authority of Dr. Muller, the eminent Government botanist, have
exceeded four hundred feet. One, indeed, reached the enormous
height of four hundred and eighty feet, thus overtopping the tallest
Sequoia by one hundred and fifty-five feet. And in diameter, also,
there are trees which exceed the Big Tree, as, for example, the
Baobab; but these are always comparatively low, rarely reaching the
height of more than sixty or seventy feet, while their excessive
diameter comes from a peculiarly swollen and distorted base. On the
whole, we may safely claim that no known tree in the world equals
the California Big Trees in the combined elements of size and height,
and in consequent grandeur, unless, indeed, it may be the
Eucalyptus. The largest Australian tree yet reported, is said to be
eighty-one feet in circumference, four feet from the ground. This is a
highly respectable vegetable, but not quite equal to the certified
measurements of some of the largest of the California Big Trees.
So the American tourist through the wonders of California, may yet
claim that his country still possesses the loftiest waterfalls, the most
overpowering cliffs, and the grandest trees yet known upon the face
of the globe.
BOWER CAVE.
Bower Cave.
This is a picturesque and unique locality, and is well worth a visit.
The cave is an immense crack or sink, or both combined, in the solid
limestone of the mountaintop. At the surface it presents a somewhat
crescent-shaped opening, one hundred and thirty-three feet long,
eighty-six feet wide near the centre, and one hundred and nine feet
deep in the deepest place. Trees grow from the bottom and lift their
branches out through the opening at the top, while a beautifully
tranquil and wonderfully clear lake occupies the greater portion of
the floor.
We enter at the north end and go down by a rough but strong and
safe staircase. The walls of the cleft are perpendicular, or nearly so,
throughout the greater portion of their extent, but near the south
end the upper part of the wall projects or overhangs several feet.
The bottom has the form of an irregular square, measuring over a
hundred feet one way and somewhat less than a hundred the other.
From the bottom and near the centre grow three large maples, the
largest of which is more than two feet through, and about a hundred
and twenty-five feet high. Around these trees are benches, capable
of seating a score or two of persons. On one side of the wall, some
twenty feet above the bottom, is a singular niche or alcove which
has been christened the "Pulpit." It is occasionally used for the
legitimate purpose of similar constructions, though more frequently
occupied by the fiddler of some festive party. Upon special
occasions, such as a Fourth of July celebration, they erect tables
here and use all the available floor as a dining hall. Over a hundred
have thus dined here at one time.
In one corner, and nearly under the pulpit, is a small but singularly
beautiful lake, rendered somewhat ghostly and mysterious by the
overhanging rocky wall, and the intercepted light falling through the
overshadowing trees. Upon this lake is a small boat, in which the
imaginative visitor may easily fancy himself crossing the Styx, with
himself as his own Charon. Not far from the corner of this lake,
nearly under the pulpit, the water is claimed to have an immense
depth. In all parts it is so clear that one can plainly see the cracks
and crevices in the sloping limestone sides at the depth of forty feet.
The vision would, doubtless, penetrate much deeper did not the
overhanging walls obstruct the light.
Having rowed across the lake, as you are returning to the shore, the
guide may possibly ask you to keep very quiet while he calls and
feeds his fish. He gives a few soft whistles, places his hand in the
water, waits a moment, repeats his whistle, and softly whispers,
"Here they come." Up swim several large trout, rub their noses
against his hand, and circle slowly around it, evidently waiting for
the customary food. And that hand seldom disappoints them. It is a
pleasant and restful sight. After enjoying it, seeing them finish
feeding, and returning to the landing, you ask the guide how they
became so tame. He tells you, that for several weeks after putting
them into the lake, which he did some years ago, he came every
day, about the same time, softly whistling and gently dropping
crumbs and worms into the water. After a few days he began to hold
on to one end of a worm while the trout would swim up, take hold of
the other end and tug away until he pulled it apart, or the hand let
go. After a few months they seemed to have learned to associate
the whistling and the feeding, so that whenever they hear the first
they swim up in evident expectation of the second.
At various heights upon one wall several large cavities or small caves
are worn into the rock, some of which admit the tourist for a
considerable distance. These make that side of the wall a collection
of cells, some of which are high enough to permit the visitor to walk
erect; others so low that they compel one who would enter to crawl
upon his hands and knees. When first discovered, the walls of these
chambers were covered with beautiful stalactites of various sizes and
fanciful forms, but the ruthless hands of vandal visitors have
gradually broken them off and carried them away, until hardly a
trace of their original beauty and variety remains.
During the heat of the summer, the time when nearly all visitors
enter this cave, its cool and refreshing temperature makes it a
comfortable and welcome retreat, especially during the hotter
midday hours. The place seems as if nature and art had combined to
make it as attractive as possible for hot weather picnics, or
midsummer lunch parties. It is difficult to imagine, and almost
impossible to discover a more fascinating combination of dell and
grotto, grove and lake, cave and bower, than nature has kindly
provided for the tourist in the romantic Bower Cave.
ALABASTER CAVE.
Dungeon of Enchantment.
Before us is a broad, oddly-shaped and low-roofed chamber, about
one hundred and twenty feet long, by seventy in width, and from
four to twenty feet high.
Bright coral-like stalactites hang down in irregular rows and in
almost every variety of shape and shade, from milk-white to cream
color; forming a most agreeable contrast with the dark arches and
the frowning buttresses on either hand, while low-browed ridges,
some almost black, others of a reddish-brown, stretch from either
side, the space between which is ornamented with a peculiar kind of
coloring which nearly resembles a grotesque species of graining.
Descending toward the left, we approach one of the most singularly
beautiful groups of stalactites in this apartment. Some of these are
fine pendants, hardly larger than pipestems, from two to five feet
long, and hollow from end to end. When the cave was first
discovered there were four or five of these pendants over eight feet
long, but the early admitted vandals ruthlessly destroyed, or selfishly
carried them off. Others resemble the ears of white elephants, or,
rather, the white elephant of Siam, while others still present the
appearance of long and slender cones, inverted.
Examining this and other groups more closely, we discover at their
bases coral-like excrescences of great beauty; here, like petrified
moss, brilliant, and almost transparent; there, a pretty fungus,
tipped and spangled with diamonds; yonder, miniature pine trees,
which, with a most obliging disposition to accommodate themselves
to circumstances, grow bottom up. In other places appear fleeces of
the finest merino or silky floss.
Leaving these, and turning to the right, we can ascend a ladder into
the loftiest part of this chamber. Here new combinations of beauty
surprise and delight us. Thence passing on, we come to a large
stalagmite, whose form and size suggest a tying post for horses.
This has been dignified, or mystified, anything but beautified, by
different names, more or less appropriate. One is "Lot's Wife." If the
woman was no higher than the stalagmite she must have been a
dwarf, for the top of the post is but four feet and a quarter above its
bottom, while its diameter at the bottom is hardly one foot. Its two
other names, "Hercules' Club," and "Brobdignag's Forefinger," are
more appropriate, though the latter would suggest an
"exaggeration," as Mrs. Partington would have it.
Continuing on, we pass over a gently rising floor resembling
solidified snow, until we approach the verge of, and look down into,
an immense abyss, surmounted by a cavernous roof. Icicle and coral
formations depend from the roof, and a rude drapery of jet covers
the sides. Here is suspended a singular petrifaction resembling a
human heart, which looks as if it might have belonged to one of the
primitive Titans, or come from the chest of that Miltonian monster,
whose spear-shaft was like a Norway pine.
On one side of this is an elevated and nearly level natural floor, upon
which a table and seats have been temporarily erected for the
convenience of choristers, choirs or singing societies, and even for
the accommodation of public worship, should any desire to witness
or participate in it in this most beautiful of God's natural temples.
The lover of sacred music would be delighted beyond measure to
hear these "vaulted hills" resound the symphonies of Mozart, Haydn
or Mendelssohn. Scores of these pendent harps would vibrate in
unison, or echo them in delicious harmonies from chamber to
chamber, or bear them from roof to wall in diminishing
reverberations even to the most remote of these rock-formed
corridors.
We may not linger here too long, so passing hence, we enter other
and smaller chambers, along whose roofs we trace formations that
resemble streams of water suddenly arrested in their flow and
turned to ice. In another, a peculiarly shaped petrifaction presents a
perfectly formed beet from one point of view, while from another it
resembles a small elephant's head. Not far hence, a bell-shaped
hollow, a beautiful combination of grotto and arcade, has received
the name of "Julia's Bower."
Once more advancing, a narrow, low-roofed passage brings us into
the most beautiful chamber of all, the
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.
ebookbell.com