PDF Basics of Python Programming 2nd Edition Dr. Pratiyush Guleria Download
PDF Basics of Python Programming 2nd Edition Dr. Pratiyush Guleria Download
com
https://ebookgate.com/product/basics-of-python-
programming-2nd-edition-dr-pratiyush-guleria/
OR CLICK HERE
DOWLOAD NOW
https://ebookgate.com/product/php-beginner-s-practical-guide-1st-
edition-pratiyush-guleria/
ebookgate.com
https://ebookgate.com/product/expert-python-programming-2nd-edition-
jaworski/
ebookgate.com
https://ebookgate.com/product/core-python-programming-2nd-edition-
wesley-chun/
ebookgate.com
https://ebookgate.com/product/python-programming-4th-edition-singh-a/
ebookgate.com
Learning BeagleBone Python Programming Unleash the
potential of BeagleBone using Python 1st Edition Hiam
https://ebookgate.com/product/learning-beaglebone-python-programming-
unleash-the-potential-of-beaglebone-using-python-1st-edition-hiam/
ebookgate.com
https://ebookgate.com/product/foundations-of-python-network-
programming-third-edition-brandon-rhodes/
ebookgate.com
https://ebookgate.com/product/foundations-of-python-network-
programming-3rd-edition-brandon-rhodes/
ebookgate.com
https://ebookgate.com/product/programming-python-3rd-ed-edition-mark-
lutz/
ebookgate.com
https://ebookgate.com/product/ultimate-python-programming-1st-edition-
deepali-srivastava/
ebookgate.com
Basics of Python
Programming
2nd Edition
www.bpbonline.com
Second Revised and Updated Edition 2024
ISBN: 978-93-55516-404
The information contained in this book is true to correct and the best of
author’s and publisher’s knowledge. The author has made every effort to
ensure the accuracy of these publications, but publisher cannot be held
responsible for any loss or damage arising from any information in this
book.
Almighty God
My beloved parents
and
My beloved family
About the Author
Residing in Noida with his family, Peyush balances his love for
technology with an unwavering commitment to family values.
Acknowledgement
Finally, I would like to thank all the readers who have taken an interest in
my book and for their support in making it a reality. Your encouragement
has been invaluable.
Preface
Chapter 3: Arrays and Functions - Arrays are the variables having similar
data types. Arrays in Python contain values corresponding to the same
data types, whereas lists, which are somewhat similar to arrays discussed
in the next chapter, contain values corresponding to different data types.
Arrays can contain more than one value at a time, and indexing is used to
refer to array elements. A function in Python is a block of a series of
statements that carry out a single or several actions. Code is easier to read,
comprehend, and maintain when it is divided into usable, modular chunks
because of the use of functions. The ability to reuse code is one benefit of
utilizing functions.
Chapter 6: File Handling and Databases - This chapter will cover the
topics related to file handling and databases. File handling in Python
enables one to work with files using the built-in functions and libraries. In
databases, we will discuss the concept of data definition language (DDL)
and data manipulation language (DML) commands for database
connections.
Chapter 10: NumPy and TKinter - By going through this chapter, learners
will acquire the knowledge of Numpy and perform operations on arrays
using Numpy. Apart from that, you will be able to work with a GUI-based
environment of Python known as Tkinter.
https://rebrand.ly/e0c1e2
The code bundle for the book is also hosted on GitHub at In case there’s
an update to the code, it will be updated on the existing GitHub repository.
We have code bundles from our rich catalogue of books and videos
available at Check them out!
Errata
We take immense pride in our work at BPB Publications and follow best
practices to ensure the accuracy of our content to provide with an
indulging reading experience to our subscribers. Our readers are our
mirrors, and we use their inputs to reflect and improve upon human errors,
if any, that may have occurred during the publishing processes involved.
To let us maintain the quality and help us reach out to any readers who
might be having difficulties due to any unforeseen errors, please write to
us at :
[email protected]
Your support, suggestions and feedbacks are highly appreciated by the
BPB Publications’ Family.
Did you know that BPB offers eBook versions of every book published,
with PDF and ePub files available? You can upgrade to the eBook version
at www.bpbonline.com and as a print book customer, you are entitled to a
discount on the eBook copy. Get in touch with us at :
At you can also read a collection of free technical articles, sign up for a
range of free newsletters, and receive exclusive discounts and offers on
BPB books and eBooks.
Piracy
If you come across any illegal copies of our works in any form on the
internet, we would be grateful if you would provide us with the location
address or website name. Please contact us at [email protected]
with a link to the material.
If there is a topic that you have expertise in, and you are interested in
either writing or contributing to a book, please visit We have worked with
thousands of developers and tech professionals, just like you, to help them
share their insights with the global tech community. You can make a
general application, apply for a specific hot topic that we are recruiting an
author for, or submit your own idea.
Reviews
Please leave a review. Once you have read and used this book, why not
leave a review on the site that you purchased it from? Potential readers
can then see and use your unbiased opinion to make purchase decisions.
We at BPB can understand what you think about our products, and our
authors can see your feedback on their book. Thank you!
Join the book’s Discord Workspace for Latest updates, Offers, Tech
happenings around the world, New Release and Sessions with the
Authors:
https://discord.bpbonline.com
Table of Contents
Introduction
Structure
Objectives
Python installation
Exploring Python
Python datatypes
Example 1.5: Example of integer, float, string datatypes, and type
conversion
Operators in Python
Relational operators
Example 1.8 Example of logical, bitwise, left shift, right shift and
assignment operators
Identity operators
Membership operators
Precedence of operators
Conclusion
Points to remember
Exercises
Introduction
Structure
Objectives
If condition
Loops
Example 2.6: Sum of first five numbers using the while loop
Example 2.12: Print the numbers using range() function in for loop
Example 2.13: Write a program to display odd numbers using for loop
Example 2.16: Program to find the sum of all numbers stored in a list
using for loop
Example 2.17: Finding prime number taking input from the user
Conclusion
Questions
Points to remember
Introduction
Structure
Objectives
Arrays
Example 3.1: Write a program for arrays using append() function
Functions
Lambda function
Conclusion
Points to remember
Exercises
Introduction
Structure
Objectives
Lists
Example 4.2: Example of slicing a list and for storing multiple data items
Example 4.3: Example of Slicing using double colon for list sequences
Tuples
Python iterators
Python generators
Sets
Points to remember
Exercises
Introduction
Structure
Objectives
Dictionaries in Python
Nested dictionary
Modules
Conclusion
Points to remember
Exercises
Introduction
Structure
Objectives
Databases
Conclusion
Points to remember
Exercises
7. Object-Oriented Programming
Introduction
Structure
Objectives
Inheritance
Example 7.3: Writing a program for inheritance
Overriding
Encapsulation
Conclusion
Points to remember
Exercises
Introduction
Regular expression for pattern matching
Example 8.9: Write a program to obtain the calendar month using calendar
module
Conclusion
Points to remember
Exercises
9. Exception Handling
Introduction
Objectives
Exception
Example 9.2: Program of exception error raised due to different data types
Conclusion
Points to remember
Exercises
Introduction
Structure
Objectives
Example 10.2: Finding sum, mean, max, and min functions using NumPy
Example 10.7: Example of taking input from a user using the text field
Conclusion
Points to remember
Exercises
Sample programs
Output prediction
Index
C
HAPTER
1
Introduction to Python Variables, Datatypes and Operators
Introduction
Lists, tuples, and dictionaries are the three basic data structures used in
Python to store and manage collections of data. Besides that, topics like
modules, object-oriented programming features, databases, file handling,
and Numpy are addressed in this book with the help of simple and
illustrative examples.
Structure
Variable declaration
Data types
Operators
type() function
Objectives
In this chapter, learners will come to know about Python software, its
installation and writing programs in IDLE. Going through this chapter, we
will cover the fundamentals of variable declaration, datatypes and so on.
Apart from it, Python operators are illustrated with the help of suitable
examples.
Python installation
After executing the Python software, the setup of the software starts its
installation progress and finally displays the completion message of the
installation, as shown in Figure
Figure 1.3: Setup installed successfully
After the Python setup is completed successfully, the Python IDLE 3.11
environment for writing programs is shown in Figure 1.4 and Figure The
IDLE is known as the integrated development learning environment. It is a
Graphical user interface for writing Python programs. Take a look at the
following figure:
Figure 1.4: Opening IDLE (Python 3.11)
Among the widely used tools in the Python development ecosystem are
PyCharm, Anaconda, and Visual Studio Code (VS each with a distinct
function.
The Anaconda software comes with Python software along with built-in
libraries of Python. This software consists of two popular IDE integrated
development environments which are Spyder and Jupyter Notebook, shown
in Figure 1.9 and Figure Interactive coding and output visualization are
hallmarks of Jupyter notebooks. Each cell’s output is retrieved along with the
code in Jupyter, which divides the code into cells. For exploratory analysis
and model construction, it is perfect because it supports interactive
development. The extension of a Jupyter code file is (.ipynb). Take a look at
the following figure:
Figure 1.9: Spyder environment window
To create web Web applications can be developed in Python with the help
of Flask and Django modules.
To handle big Python can be easily integrated with Big Data Frameworks.
The steps to run the Python programs on IDLE Shell are as follows:
Language: English
BY
LIEUT. JAMES K. ORTON
Author of “The Last Chance Mine,” “Beach Boy Joe,” etc.
PHILADELPHIA
DAVID McKay, PUBLISHER
610 South Washington Square
Copyright, 1902
By STREET & SMITH
The Secret Chart
CONTENTS.
Chapter Page
I.—A Discovery 5
II.—At Sea 13
III.—A Message 21
IV.—The Castaways 29
V.—Mischief 37
VI.—Mutiny 45
VII.—Set Adrift 53
VIII.—Turning the Tables 61
IX.—Bound South 69
X.—Hayti 77
XI.—Conjectures 85
XII.—A Strange Spectacle 93
XIII.—In Trouble 101
XIV.—The Cave 109
XV.—A Discovery 117
XVI.—Andy 125
XVII.—A Successful Scheme 133
XVIII.—Treasure Hunting 141
XIX.—The Wreck 149
XX.—The Underground Passage 157
XXI.—A Trap 165
XXII.—Run to Cover 173
XXIII.—Secret of the Cave 181
XXIV.—The Treasure Chamber 189
XXV.—To the Rescue 197
XXVI.—A Pitched Battle 205
XXVII.—Under Cover 213
XXVIII.—A Second Alarm 221
XXIX.—In the Tunnel 229
XXX.—The Story 237
XXXI.—An Opportune Arrival 244
XXXII.—The Departure 252
THE SECRET CHART.
CHAPTER I.
A DISCOVERY.
Near the mouth of Spuyten Duyvil Creek the yacht Day Dream lay at
anchor on a certain day in September, two years ago.
The driving rain only served to give her white hull, with its trimmings
of gold, an additional luster, bringing into yet bolder relief the
polished mahogany and walnut inboard woodwork.
Two sailors and an old colored steward remained below to escape an
unnecessary wetting, and the fifty-ton beauty tugged at the cable as
if trying to escape from her moorings before her caretakers should
be aware of the fact.
On the river bank, half-hidden by a clump of trees, was the old stone
house owned by Henry Mansfield, formerly a captain in the China
trade, but now retired. Having accumulated considerable wealth, he
believed it would be more pleasant to remain ashore permanently;
but, after a short time of idleness, his love for the sea returned with
redoubled force, and, as a result, the Day Dream was purchased.
On her the captain spent considerably more than half his time, and
now the little craft was provisioned for a long southern cruise, much
to the delight of the owner’s son Gilbert, and his nephew, Nelson
Duncan, who had, after no slight difficulty, succeeded in gaining
permission to make the voyage.
The boys were on shore overhauling their traps, preparatory to
leaving early next morning, and having considerable trouble in
deciding just what should be left behind.
“We’ve laid out a big pile of stuff,” Gilbert said, as he surveyed the
guns, fishing tackle, clothes, and a general assortment of odds and
ends, which both he and his cousin had thought would be necessary
to their comfort and pleasure during the voyage; “but if we throw
anything out, it will be just what we may want most when the yacht
is at sea.”
“But how are we to get so much aboard?”
“In case your trunk and mine won’t hold it all, there’s an old chest in
the attic, which will be the very ticket. If it doesn’t stop raining
pretty soon, we’ll have to get a piece of tarpaulin to cover them
while going out to the schooner.”
That the old chest would be needed was learned very soon, and Gil
said, with a sigh:
“There’s no question but that something must be left. We’ll pack the
most important, and then decide as to the rest. Come on, it won’t
take long to overhaul what is in the attic.”
The only idea in the minds of the boys was to secure that which
would serve as a receptacle for their goods until the same could be
carried to the schooner, and, on finding the well-worn chest, it was
only natural to first make sure that it was empty.
The rusted lock was fastened, and, eager to complete the work as
soon as possible, Gil knocked the hasp off by kicking at it, after
which the lid was thrown open.
At first glance one would have said that it contained nothing, but on
turning it upside down several articles rolled out.
Idle curiosity, rather than a belief that anything important would be
found, caused the boys to pick up the contents, and Nelse cried, as
he went toward the window:
“Say, Gil, here’s a piece of an old newspaper, containing what
appears to be an old story. Where did the chest come from?”
“I don’t know. Read what you have found, if it is interesting.”
“There is a long account here, but if you can keep quiet a few
moments, I’ll make it out, in spite of the many creases and the dirt.”
Then Nelse began the following:
“North of that wild promontory which projects itself into the tropic
waters of the Mexican Gulf at the northwestern extremity of Hayti,
and four miles to seaward of the ancient town, lies a rocky inlet
known as Tortuga de Mar. In size and aspect it is insignificant. Yet,
lilliputian and unfamiliar though it now is, it gave birth to the most
merciless and picturesque class of marine cutthroats known to
history.”
“Keep that until we start,” Gil said, impatiently, as his cousin paused
to take a long breath. “Just now we want to get our traps aboard,
instead of reading some musty tale.”
“Wait a moment, and find out what it means. We’ve got plenty of
time,” Nelse said, and then he continued:
“Back in the opening decades of the seventeenth century
adventurous criminals from throughout the Antilles began to collect
on the islet, and in a few years Tortuga became the recognized
headquarters of the Spanish Main. From it as from a fever germ
went out a fire of blood, piracy, and lawlessness which spread over
the waters of the Western World.
“Tortuga was settled in the first years of this century by Spanish
pioneers from the island known as Hispanola, or ‘Little Spain.’ It was
given the fanciful name of Tortuga de Mar, ‘The Sea Tortoise,’ from
its resemblance in shape to that amphibian. The settlers were a
worthy and simple folk, for the most part fishermen, who, for a few
months in the twelve, varied life by hunting the wild cattle which fed
in the wooded coast lands.
“Scarcely had they become well established on the Tortoise, when,
one morning in May, 1632, they were mystified at the sight of a
pinnace load of strange seamen landing on the key which faces the
mouth of their harbor. Fifteen restless spirits from the French colony
of St. Christopher had, with the adventurous recklessness which
marked that day and those waters, set out for the best location
which fortune and a west wind should put in their way. They were
allowed to put up sapodilla shelters at the harbor mouth, and also to
shoot their French bullets into wild bulls on the opposite coast.
“In a few weeks it became evident that the rascally strangers could
slaughter and boucan more beeves in a day than the entire Spanish
community could in three. Boucanning, by the way, was a peculiar
process of curing flesh by jerking, salting, and drying in the
sunshine, the term being derived from an aboriginal word applied by
the cannibal Caribbes to the curing of human flesh. Such was the
skill of the intruders in converting the bulls into a superior,
merchantable product by means of the boucan that the Spanish
derisively applied the native word to them.
“As Tortuga lay directly in the path of European vessels bound for
Mexican ports, the fifteen Frenchmen immediately built up a thriving
business in boucanned beef. Doubloons, pieces-of-eight, and
moidores became to them as shells or seabeans to the Spanish
fishermen. Word went back apace to St. Christopher, throwing that
island into such an uproar that the craze to go a-boucanning carried
its most unruly seamen to the Tortoise.
“Frenchmen came down upon the islet like a swarm of mosquitoes,
and overran it before the simple Spanish folks could recover from
their astonishment. Ominous growlings were heard among the
original settlers, but for such trivial matters as round Spanish oaths
the intruders cared never a whit. Just before dawn, December 1,
1633, the Spanish islanders met at the plaza of their little town, and
descended headlong upon the intruders at the boucanning beaches.
Then began a massacre, during which the intruders were cut down
wherever found.
“Immediately after this the boucanning foreigners formed
themselves into a band composed of a collection of couples. Each
two hunters made common property of all possessions of either.
They bound themselves by every oath to an imperishable
brotherhood. Each swore to avenge with death any insult offered to
the other. The two hunted and lived together by day, slept together
by night, and were as one flesh; and always as the band ranged the
coast valleys, grew the purpose of avenging the Tortuga massacre.
“A few months later the Frenchmen took the islanders by surprise. A
carnival of butchery ensued. When it was completed the village was
burned. The most lawless of the murderers was one Pierre Le Gros,
a sailor of oxlike frame and weight, hailing originally from Dieppe,
who, with twenty-seven fellow spirits, stole a small sloop from a
Tortugan skipper, and started on a nautical foray on whatsoever
Spanish merchantmen fate might cast in his course.
“The act was of sufficient gravity to daunt even the chosen crew of
cutthroats captained by Pierre, had the proposed prey been anything
but Spanish, since it was plain piracy. For two days the sloop ran on
before a northerly wind, swinging down into the Caribbean Sea, but
sighting no craft. On the third afternoon out Pierre spied a galleon,
one of the Panama pearl fleet, which had been separated from its
sister vessels in a recent hurricane. Until night shut down, he craftily
kept away toward the windward horizon. Then, under cover of the
darkness, he swiftly and silently approached, coming alongside at
daybreak. The entire twenty-eight buccaneers boarded the galleon,
leaving their sloop adrift.
“Six men rushed headlong to the gunroom, taking immediate
possession. Six more went to the clumsy steering apparatus, while
Pierre, with the remaining fifteen, hove the morning watch
overboard and made for the cabin. On bursting into the captain’s
room, Pierre found the worthy Don playing at cards with his officers,
and discussing a goodly measure of Madeira.
“Before the captain could speak, the pirates swarmed into the
apartment, and covered the group with their pistols. In less than
three minutes the prize was theirs. The crew were marooned, and
the galleon taken to France, where, she and her cargo quickly
disposed of, the buccaneers left with all speed to rendezvous at the
Tortuga.
“When the intelligence of this exploit reached the Tortoise, the entire
island was thrown into a hubbub. Nothing was thought of but to go
buccaneering for galleons. Brig after brig and ship after ship were
fitted out, and in a year this species of piracy became a recognized
business. Ten years later the Spanish commerce in these waters had
been almost entirely destroyed. The sea was forsaken for the richer
prizes on land. The rich capital of Campeche was sacked, to be, in
turn, followed by Panama, and the curers of beef had become such
a power as to attract the attention of every nation.”
“Is that all?” Gil asked, as Nelse ceased reading.
“Every word, and it isn’t such a bad sort of story, except that there’s
not more than half enough. I wonder why your father has been
keeping it in the chest?”
“I don’t believe he knew it was here. But look at the rest of this
stuff! Do you suppose these have anything to do with the piece of
newspaper?”
As he spoke, Gil picked up the other articles, and he and Nelse were
gazing at them in perplexity when Captain Mansfield entered the
attic.
CHAPTER II.
AT SEA.
“Well, what are you boys hunting for? Pirates’ gold?” Captain
Mansfield asked, with a hearty laugh, as he looked over Gil’s
shoulder.
“We came here for this old chest, because our trunks won’t hold all
we want to carry, and in it found these things, which I don’t suppose
amount to anything; but I can’t make out why you or any one else
would want to keep them.”
As he spoke, Gil laid on the lid of the box the different, apparently
useless, articles which had fallen out when the hasp was broken.
They all had that peculiar musty, salty odor, which tells of months
spent in the forecastle, while the good ship plows her way across
this or that ocean, one day aided by favoring winds, and on the next
battling for life with the spirit of the tempest.
First the newspaper story was placed before Captain Mansfield; then
a small coil of thin, well-waxed cord; then a piece of hard, dark-
colored wood about four inches long by two wide, with the following
marks rudely cut, as if with a sheathknife:
ebookgate.com