Instant download Programming and Problem Solving with Python Ashok Namdev Kamthane pdf all chapter
Instant download Programming and Problem Solving with Python Ashok Namdev Kamthane pdf all chapter
com
https://ebookmass.com/product/programming-and-problem-
solving-with-python-ashok-namdev-kamthane/
OR CLICK BUTTON
DOWNLOAD NOW
https://ebookmass.com/product/problem-solving-and-python-programming-
e-balagurusamy/
ebookmass.com
https://ebookmass.com/product/python-programming-using-problem-
solving-approach-1st-edition-reema-thareja/
ebookmass.com
https://ebookmass.com/product/programming-for-problem-solving-e-
balagurusamy/
ebookmass.com
https://ebookmass.com/product/introduction-to-programming-with-java-a-
problem-solving-approach-3rd-edition-john-dean/
ebookmass.com
Introduction To Computing And Problem Solving Using Python
1st Edition E. Balaguruswamy
https://ebookmass.com/product/introduction-to-computing-and-problem-
solving-using-python-1st-edition-e-balaguruswamy/
ebookmass.com
https://ebookmass.com/product/matlab-a-practical-introduction-to-
programming-and-problem-solving-4th-edition-stormy-attaway/
ebookmass.com
https://ebookmass.com/product/learning-scientific-programming-with-
python-hill/
ebookmass.com
https://ebookmass.com/product/mastering-functional-programming-with-
python-brett-neutreon/
ebookmass.com
https://ebookmass.com/product/python-programming-and-sql-10-books-
in-1-supercharge-your-career-with-python-programming-and-sql-andrew-
reed/
ebookmass.com
PROGRAMMING AND PROBLEM SOLVING
WITH
PYTHON
About the Authors
PYTHON
Ashok Namdev Kamthane
Retired Associate Professor
Department of Electronics and Telecommunication Engineering
Shri Guru Gobind Singhji Institute of Engineering and Technology, Nanded
Maharashtra, India
1 2 3 4 5 6 7 8 9 D103074 22 21 20 19 18
Printed and bound in India.
Print Edition
ISBN (13): 978-93-87067-57-8
ISBN (10): 93-87067-57-2
e-Book Edition
ISBN (13): 978-93-87067-58-5
ISBN (10): 93-87067-58-0
Managing Director: Kaushik Bellani
Director—Science & Engineering Portfolio: Vibha Mahajan
Senior Portfolio Manager—Science & Engineering: Hemant K Jha
Associate Portfolio Manager—Science & Engineering: Mohammad Salman Khurshid
Senior Manager—Content Development: Shalini Jha
Content Developer: Ranjana Chaube
Production Head: Satinder S Baveja
Assistant Manager—Production: Jagriti Kundu
General Manager—Production: Rajender P Ghansela
Manager—Production: Reji Kumar
Information contained in this work has been obtained by McGraw Hill Education (India), from sources believed to be reliable.
However, neither McGraw Hill Education (India) nor its authors guarantee the accuracy or completeness of any information
published herein, and neither McGraw Hill Education (India) nor its authors shall be responsible for any errors, omissions, or
damages arising out of use of this information. This work is published with the understanding that McGraw Hill Education
(India) and its authors are supplying information but are not attempting to render engineering or other professional services. If
such services are required, the assistance of an appropriate professional should be sought.
Typeset at APS Compugraphics, 4G, PKT 2, Mayur Vihar Phase-III, Delhi 96, and printed at
Cover Printer:
It gives us immense pleasure to bring the book ‘Programming and Problem Solving with Python’. The
book is intended for the students in initial years of engineering and mathematics who can use this
high-level programming language as an effective tool in mathematical problem solving. Python is
used to develop applications of any stream and it is not restricted only to computer science.
We believe that anyone who has basic knowledge of computer and ability of logical thinking can
learn programming. With this motivation, we have written this book in a lucid manner. Once you
go through the book, you will know how simple the programming language is and at the same
time you will learn the basics of python programming. You will feel motivated enough to develop
applications using python.
Since this book has been written with consideration that reader has no prior knowledge of
python programming, before going through all the chapters, reader should know what are the
benefits of learning python programming. Following are some of the reasons why one should
learn python language.
• Python language is simple and easy to learn. For example, it has simple syntax compared to
other programming languages.
• Python is an object-oriented programming language. It is used to develop desktop, standalone
and scripting applications.
• Python is also an example of free open source software. Due to its open nature one can write
programs and can deploy on any of platform, i.e., (Windows, Linux, Ubuntu and Mac OS),
without changing the original program.
Thus, due to the features enlisted above, python has become the most popular language and is
widely used among programmers.
• To develop GUI-based applications, cryptography and network security and many more
applications
Electronics and Telecommunication Engineering and Electrical Engineering
• Image processing applications can be developed by using python’s ‘scikit-image’ library
• Widely used in developing embedded applications
• Develop IOT applications using Arduino and Raspberry pi
Python can also be used in other engineering streams such as mechanical, chemical, and
bioinformatics to perform complex calculations by making use of numpy, scipy, and pandas library.
Thus, the end user of this book can be anyone who wants to learn basics of python programming.
To learn the basics, the student can be of any stream/any engineering/Diploma/BCA/MCA
background and interested to develop applications using python.
In the end, we would like to express gratitude to all our well-wishers and readers, whose
unstinted support and encouragement has kept us going as a teacher and author of this book. Any
suggestion regarding the improvement of the book will be highly appreciated.
Publisher’s Note
McGraw-Hill Education (India) invites suggestions and comments from you, all of which can be
sent to info.india@mheducation.com (kindly mention the title and author name in the subject line).
Piracy-related issues may also be reported.
Visual W
All chapters within the book have been structured into the following important pedagogical
components:
Decision Statements
• Learning Outcomes give a clear idea to the 4
students and programmers on what they will
learn in each chapter. After completion of 4.1 Introduction
CHAPTER OUTLINE
4.6 Boolean Expressions and Relational
4.2 Boolean Type Operators
chapter, they will able to comprehend and apply 4.3
4.4
Boolean Operators
Using Numbers with Boolean Operators
4.7 Decision Making Statements
4.8 Conditional Expressions
all the objectives of the chapter. 4.5 Using String with Boolean Operators
LEARNING OUTCOMES
• Introduction explains the basics of each topic After completing this chapter, students will be able to:
bool
and familiarizes the reader to the concept being Boolean Relational > <,>= <= !=
if
dealt with. if
if else
if-elif-else
conditional expressions
4.1 INTRODUCTION
Write a program to create a list with elements 1,2,3,4 and 5. Display even elements of the list
PROGRAM 8.1 using list comprehension.
List1=[1,2,3,4,5]
print(“Content of List1”)
print(List1)
List1=[x for x in List1 if x%2==0]
print(“Even elements from the List1”)
print(List1)
• Programs are the highlighting
Output Generate 50 random numbers within a range 500 to 1000 and write them to file
feature of the chapters. Ample
PROGRAM 13.3
Content of List1
[1, 2, 3, 4, 5]
WriteNumRandom.txt.
Output File
Visual Walkthrough xi
penup(), pendown(),
forward(), right(), goto(), color(), shape(), speed() left()
Note: The del operator uses index to access the elements of a list. It gives a run time error if the index
• Notes have been inserted in each chapter
is out of range.
Example: to provide valuable insights based on
>>> del Lst[4]
Traceback (most recent call last):
programming concepts. Notes shall
File “<pyshell#37>”, line 1, in <module>
del Lst[4]
also act as precautionary statements for
IndexError: list assignment index out of range readers to solve programming problems
effectively.
SUMMARY
• A concise Summary has been listed at
chapter-end to reiterate vital points and
describes in short, the complex concepts
covered within the chapter.
x = 10
def f():
x= x + 10
print(x)
f()
Acknowledgements
We would like to express deep sense of gratitude to Professor B. M. Naik, former Principal of
S. G. G. S. College of Engineering and Technology, Nanded, who constantly praised and inspired
us to write books on technical subjects and whose enthusiasm and guidance led us to write this
book.
Special thanks are also due to Dr. L. M. Waghmare, Director, S. G. G. S. Institute of Engineering
and Technology, Professor Dr. U. V. Kulkarni, HOD, CSE and Professor P. S. Nalawade of S. G. G. S.
Institute of Engineering and Technology Nanded for encouraging us to write this book on Python.
We are grateful to Professor Dr. Mrs. S. A. Itkar, HOD, CSE and Professor Mrs. Deipali V. Gore
of P. E. S. Modern College of Engineering Pune, for supporting us while writing the book. We
are also thankful to the staff members (Santosh Nagargoje, Nilesh Deshmukh, Kunnal Khadake,
Digvijay Patil and Sujeet Deshpande) of P. E. S. Modern College of Engineering for their valuable
suggestions.
Furthermore, we would like to thank our friends—ShriKumar P. Ugale and Navneet Agrawal—
for giving valuable inputs while writing the book. Also, we would like to thank our students—
Suraj K, Pranav C, and Prajyot Gurav—who offered comments, suggestions and praise while
writing the book.
We are thankful to the following reviewers for providing useful feedback and critical suggestions
during the development of the manuscript.
Lastly, we are indebted to our family members—Mrs. Surekha Kamthane (mother of Amit
Kamthane), Amol, Swarupa, Aditya, Santosh Chidrawar, Sangita Chidrawar, Sakshi and Sartak for
their love, support and encouragement.
The savour of the spring is still in the English May songs, the
French maierolles or calendes de mai and the Italian calen di
maggio. But for the rest they have either become little but mere
quête songs, or else, under the influence of the priests, have taken
on a Christian colouring[556]. At Oxford the ‘merry ketches’ sung by
choristers on the top of Magdalen tower on May morning were
replaced in the seventeenth century by the hymn now used[557].
Another very popular Mayers’ song would seem to show that the
Puritans, in despair of abolishing the festival, tried to reform it.
Another religious element, besides prayer, may have entered into the
pre-Christian festival songs; and that is myth. A stage in the
evolution of drama from the Dionysiac dithyramb was the
introduction of mythical narratives about the wanderings and
victories of the god, to be chanted or recited by the choragus. The
relation of the choragus to the chorus bears a close analogy to that
between the leader of the mediaeval carole and his companions who
sang the refrain. This leader probably represents the Keltic or
Teutonic priest at the head of his band of worshippers; and one may
suspect that in the north and west of Europe, as in Greece, the
pauses of the festival dance provided the occasion on which the
earliest strata of stories about the gods, the hieratic as distinguished
from the literary myths, took shape. If so the development of divine
myth was very closely parallel to that of heroic myth[559].
After religion, the commonest motif of dance and song at the
village festivals must have been love. This is quite in keeping with
the amorous licence which was one of their characteristics. The
goddess of the fertility of earth was also the goddess of the fertility
of women. The ecclesiastical prohibitions lay particular stress upon
the orationes amatoriae and the cantica turpia et luxuriosa which the
women sang at the church doors, and only as love-songs can be
interpreted the winileodi forbidden to the inmates of convents by a
capitulary of 789[560]. The love-interest continues to be prominent in
the folk-song, or the minstrel song still in close relation to folk-song,
of mediaeval and modern France. The beautiful wooing chanson of
Transformations, which savants have found it difficult to believe not
to be a supercherie, is sung by harvesters and by lace-makers at the
pillow[561]. That of Marion, an ironic expression of wifely submission,
belongs to Shrove Tuesday[562]. These are modern, but the
following, from the Chansonnier de St. Germain, may be a genuine
mediaeval folk-song of Limousin provenance:
‘A l’entrada dal tems clar, eya,
Per joja recomençar, eya,
Et per jelos irritar, eya,
Vol la regina mostrar
Qu’el’ es si amoroza.
Alavi’, alavia jelos,
Laissaz nos, laissaz nos
Ballar entre nos, entre nos[563].’
The ‘queen’ here is, of course, the festival queen or lady of the May,
the regina avrillosa of the Latin writers, la reine, la mariée,
l’épousée, la trimousette of popular custom[564]. The defiance of the
jelos, and the desire of the queen and her maidens to dance alone,
recall the conventional freedom of women from restraint in May, the
month of their ancient sex-festival, and the month in which the
mediaeval wife-beater still ran notable danger of a chevauchée.
The amorous note recurs in those types of minstrel song which
are most directly founded upon folk models. Such are the chansons
à danser with their refrains, the chansons de mal mariées, in which
the ‘jalous’ is often introduced, the aubes and the pastourelles[565].
Common in all of these is the spring setting proper to the chansons
of our festivals, and of the ‘queen’ or ‘king’ there is from time to time
mention. The leading theme of the pastourelles is the wooing,
successful or the reverse, of a shepherdess by a knight. But the
shepherdess has generally also a lover of her own degree, and for
this pair the names of Robin and Marion seem to have been
conventionally appropriated. Robin was perhaps borrowed by the
pastourelles from the widely spread refrain
In the following century his fame as a great outlaw spread far and
wide, especially in the north and the midlands[584]. The Scottish
chronicler Bower tells us in 1447 that whether for comedy or tragedy
no other subject of romance and minstrelsy had such a hold upon
the common folk[585]. The first of the extant ballads of the cycle, A
Gest of Robyn Hode, was probably printed before 1500, and in
composition may be at least a century earlier. A recent investigator
of the legend, and a very able one, denies to Robin Hood any
traceable historic origin. He is, says Dr. Child, ‘absolutely a creation
of the ballad muse.’ However this may be, the version of the
Elizabethan playwright Anthony Munday, who made him an earl of
Huntingdon and the lover of Matilda the daughter of Lord Fitzwater,
may be taken as merely a fabrication. And whether he is historical or
not, it is difficult to see how he got, as by the sixteenth century he
did get, into the May-game. One theory is that he was there from
the beginning, and that he is in fact a mythological figure, whose
name but faintly disguises either Woden in the aspect of a
vegetation deity[586], or a minor wood-spirit Hode, who also survives
in the Hodeken of German legend[587]. Against this it may be
pointed out, firstly that Hood is not an uncommon English name,
probably meaning nothing but ‘à-Wood’ or ‘of the wood[588],’ and
secondly that we have seen no reason to suppose that the mock
king, which is the part assigned to Robin Hood in the May-game,
was ever regarded as an incarnation of the fertilization spirit at all.
He is the priest of that spirit, slain at its festival, but nothing more. I
venture to offer a more plausible explanation. It is noticeable that
whereas in the May-game Robin Hood and Maid Marian are
inseparable, in the early ballads Maid Marian has no part. She is
barely mentioned in one or two of the latest ones[589]. Moreover
Marian is not an English but a French name, and we have already
seen that Robin and Marion are the typical shepherd and
shepherdess of the French pastourelles and of Adan de la Hale’s
dramatic jeu founded upon these. I suggest then, that the names
were introduced by the minstrels into English and transferred from
the French fêtes du mai to the ‘lord’ and ‘lady’ of the corresponding
English May-game. Robin Hood grew up independently from heroic
cantilenae, but owing to the similarity of name he was identified with
the other Robin, and brought Little John, Friar Tuck and the rest with
him into the May-game. On the other hand Maid Marian, who does
not properly belong to the heroic legend, was in turn, naturally
enough, adopted into the later ballads. This is an hypothesis, but
not, I think, an unlikely hypothesis.
Of what, then, did the May-game, as it took shape in the
fifteenth and sixteenth centuries, consist? Primarily, no doubt, of a
quête or ‘gaderyng.’ In many places this became a parochial, or even
a municipal, affair. In 1498 the corporation of Wells possessed
moneys ‘provenientes ante hoc tempus de Robynhode[590].’
Elsewhere the churchwardens paid the expenses of the feast and
accounted for the receipts in the annual parish budget[591]. There
are many entries concerning the May-game in the accounts of
Kingston-on-Thames during some half a century. In 1506 it is
recorded that ‘Wylm. Kempe’ was ‘kenge’ and ‘Joan Whytebrede’ was
‘quen.’ In 1513 and again in 1536 the game went to Croydon[592].
Similarly the accounts of New Romney note that in 1422 or
thereabouts the men of Lydd ‘came with their may and ours[593],’
and those of Reading St. Lawrence that in 1505 came ‘Robyn Hod of
Handley and his company’ and in 1507 ‘Robyn Hod and his company
from ffynchamsted[594].’ In contemporary Scotland James IV gave a
present at midsummer in 1503 ‘to Robin Hude of Perth[595].’ It
would hardly have been worth while, however, to carry the May-
game from one village or town to another, had it been nothing but a
procession with a garland and a ‘gaderyng’; and as a matter of fact
we find that in England as in France dramatic performances came to
be associated with the summer folk-festivals. The London ‘Maying’
included stage plays[596]. At Shrewsbury lusores under the Abbot of
Marham acted interludes ‘for the glee of the town’ at Pentecost[597].
The guild of St. Luke at Norwich performed secular as well as
miracle plays, and the guild of Holy Cross at Abingdon held its feast
on May 3 with ‘pageants, plays and May-games,’ as early as
1445[598]. Some of these plays were doubtless miracles, but so far
as they were secular, the subjects of them were naturally drawn, in
the absence of pastourelles, from the ballads of the Robin Hood
cycle[599]. Amongst the Paston letters is preserved one written in
1473, in which the writer laments the loss of a servant, whom he
has kept ‘thys iij yer to pleye Seynt Jorge and Robyn Hod and the
Shryff off Nottyngham[600].’ Moreover, some specimens of the plays
themselves are still extant. One of them, unfortunately only a
fragment, must be the very play referred to in the letter just quoted,
for its subject is ‘Robin Hood and the Sheriff of Nottingham,’ and it is
found on a scrap of paper formerly in the possession of Sir John
Fenn, the first editor of the Paston Letters[601]. A second play on
‘Robin Hood and the Friar’ and a fragment of a third on ‘Robin Hood
and the Potter’ were printed by Copland in the edition of the Gest of
Robyn Hode published by him about 1550[602]. The Robin Hood
plays are, of course, subsequent to the development of religious
drama which will be discussed in the next volume. They are of the
nature of interludes, and were doubtless written, like the plays of
Adan de la Hale, by some clerk or minstrel for the delectation of the
villagers. They are, therefore, in a less degree folk-drama, than the
examples which we shall have to consider in the next chapter. But it
is worthy of notice, that even in the hey-day of the stage under
Elizabeth and James I, the summer festival continued to supply
motives to the dramatists. Anthony Munday’s Downfall and Death of
Robert Earl of Huntingdon[603], Chapman’s May-Day, and Jonson’s
delightful fragment The Sad Shepherd form an interesting group of
pastoral comedies, affinities to which may be traced in the As You
Like It and Winter’s Tale of Shakespeare himself.
As has been said, it is impossible to establish any direct affiliation
between the Robin Hood plays and earlier caroles on the same
theme, in the way in which this can be done for the jeu of Adan de
la Hale, and the Robin and Marion of the pastourelles. The extant
Robin Hood ballads are certainly not caroles; they are probably not
folk-song at all, but minstrelsy of a somewhat debased type. The
only actual trace of such caroles that has been come across is the
mention of ‘Robene hude’ as the name of a dance in the Complaynt
of Scotland about 1548[604]. Dances, however, of one kind or
another, there undoubtedly were at the May-games. The Wells
corporation accounts mention puellae tripudiantes in close relation
with Robynhode[605]. And particularly there was the morris-dance,
which was so universally in use on May-day, that it borrowed, almost
in permanence, for its leading character the name of Maid Marian.
The morris-dance, however, is common to nearly all the village
feasts, and its origin and nature will be matter for discussion in the
next chapter.
In many places, even during the Middle Ages, and still more
afterwards, the summer feast dropped out or degenerated. It
became a mere beer-swilling, an ‘ale[606].’ And so we find in the
sixteenth century a ‘king-ale[607]’ or a ‘Robin Hood’s ale[608],’ and in
modern times a ‘Whitsun-ale[609],’ a ‘lamb-ale[610]’ or a ‘gyst-
ale[611]’ beside the ‘church-ales’ and ‘scot-ales’ which the thirteenth-
century bishops had already condemned[612]. On the other hand,
the village festival found its way to court, and became a sumptuous
pageant under the splendour-loving Tudors. For this, indeed, there
was Arthurian precedent in the romance of Malory, who records how
Guenever was taken by Sir Meliagraunce, when ‘as the queen had
mayed and all her knights, all were bedashed with herbs, mosses,
and flowers, in the best manner and freshest[613].’ The chronicler
Hall tells of the Mayings of Henry VIII in 1510, 1511, and 1515. In
the last of these some hundred and thirty persons took part. Henry
was entertained by Robin Hood and the rest with shooting-matches
and a collation of venison in a bower; and returning was met by a
chariot in which rode the Lady May and the Lady Flora, while on the
five horses sat the Ladies Humidity, Vert, Vegetave, Pleasaunce and
Sweet Odour[614]. Obviously the pastime has here degenerated in
another direction. It has become learned, allegorical, and pseudo-
classic. At the Reformation the May-game and the May-pole were
marks for Puritan onslaught. Latimer, in one of his sermons before
Edward VI, complains how, when he had intended to preach in a
certain country town on his way to London, he was told that he
could not be heard, for ‘it is Robyn hoodes daye. The parishe are
gone a brode to gather for Robyn hoode[615].’ Machyn’s Diary
mentions the breaking of a May-pole in Fenchurch by the lord mayor
of 1552[616], and the revival of elaborate and heterogeneous May-
games throughout London during the brief span of Queen Mary[617].
The Elizabethan Puritans renewed the attack, but though something
may have been done by reforming municipalities here and there to
put down the festivals[618], the ecclesiastical authorities could not be
induced to go much beyond forbidding them to take place in
churchyards[619]. William Stafford, indeed, declared in 1581 that
‘May-games, wakes, and revels’ were ‘now laid down[620],’ but the
violent abuse directed against them only two years later by Philip
Stubbes, which may be taken as a fair sample of the Puritan polemic
as a whole, shows that this was far from being really the case[621].
In Scotland the Parliament ordered, as early as 1555, that no one
‘be chosen Robert Hude, nor Lytill Johne, Abbot of vnressoun,
Quenis of Maij, nor vtherwyse, nouther in Burgh nor to landwart in
ony tyme to cum[622].’ But the prohibition was not very effective, for
in 1577 and 1578 the General Assembly is found petitioning for its
renewal[623]. And in England no similar action was taken until 1644
when the Long Parliament decreed the destruction of such May-
poles as the municipalities had spared. Naturally this policy was
reversed at the Restoration, and a new London pole was erected in
the Strand, hard by Somerset House, which endured until 1717[624].
CHAPTER IX
THE SWORD-DANCE
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookmass.com