Building Python Programs 1st Edition Stuart Reges instant download
Building Python Programs 1st Edition Stuart Reges instant download
Reges download
https://textbookfull.com/product/building-python-programs-1st-
edition-stuart-reges/
https://textbookfull.com/product/building-java-programs-a-back-
to-basics-approach-stuart-reges/
https://textbookfull.com/product/building-java-programs-a-back-
to-basics-approach-stuart-reges-2/
https://textbookfull.com/product/building-java-programs-a-back-
to-basics-approach-5th-edition-stuart-reges/
https://textbookfull.com/product/fundamentals-of-python-first-
programs-2nd-edition-kenneth-a-lambert/
Building Community and Family Resilience: Research,
Policy, and Programs Mike Stout
https://textbookfull.com/product/building-community-and-family-
resilience-research-policy-and-programs-mike-stout/
https://textbookfull.com/product/python-data-analysis-perform-
data-collection-data-processing-wrangling-visualization-and-
model-building-using-python-3rd-edition-avinash-navlani/
https://textbookfull.com/product/choppy-water-1st-edition-stuart-
woods-woods/
https://textbookfull.com/product/dendrites-3rd-edition-greg-
stuart/
https://textbookfull.com/product/the-new-mechanical-
philosophy-1st-edition-stuart-glennan/
Building Python Programs
First Edition
Stuart Reges
University of Washington
Marty Stepp
Stanford University
Allison Obourn
University of Arizona
The authors and publisher of this book have used their best efforts
in preparing this book. These efforts include the development,
research, and testing of the theories and programs to determine
their effectiveness. The authors and publisher make no warranty of
any kind, expressed or implied, with regard to these programs or to
the documentation contained in this book. The authors and publisher
shall not be liable in any event for incidental or consequential
damages in connection with, or arising out of, the furnishing,
performance, or use of these programs.
1 18
ISBN 10: 0-13-520598-0
Our new Building Python Programs text is designed for use in a first
course in computer science. We have class-tested it with hundreds
of undergraduates at the University of Arizona, most of whom were
not computer science majors. This textbook is based on our
previous text, Building Java Programs, now in its fourth edition. The
Java text has proven effective in our class testing with thousands of
students including our own at the University of Washington since
2007.
The following table shows how the layered approach works in the
first seven chapters:
Layers in Chapters 1 –7
Supplements
Answers to all self-check problems appear on our web site and are
accessible to anyone: http://www.buildingpythonprograms.com/
In addition, our web site also has the following additional resources
available for students:
Instructors can access the following resources from our web site:
MyLab Programming
MyLab Programming helps students fully grasp the logic, semantics,
and syntax of programming. Through practice exercises and
immediate, personalized feedback, MyLab Programming improves
the programming competence of beginning students, who often
struggle with the basic concepts and paradigms of popular high-level
programming languages. A self-study and homework tool, the
MyLab Programming course consists of hundreds of small practice
exercises organized around the structure of this textbook. For
students, the system automatically detects errors in the logic and
syntax of their code submissions and offers targeted hints that
enable students to figure out what went wrong—and why. For
instructors, a comprehensive gradebook tracks correct and incorrect
answers and stores the code inputted by students for review.
Acknowledgments
We would also like to thank the staff at Pearson who helped produce
the book. Rose Kernan managed the project and was our primary
point of contact during book production. Rose did a phenomenal job;
she was diligent, responsive, and helpful at every step of the
process. Amanda Brands was our content producer, and she also
provided excellent support along the way. Thank you to Martha
McMaster for proofreading the text, and thanks to Shelly Gerger-
Knechtl for copy editing and indexing. We thank Yvonne Vannatta,
our marketing manager, and Meghan Jacoby, our editorial assistant.
We also want to thank the team of artists and compositors from
Pearson’s partner institutions who helped produce the chapters of
this text.
Last but not least, the authors would like to thank the CSC 110
students at the University of Arizona who class-tested our chapters
in rough draft form. Students provided helpful suggestions for
improving the content and also submitted corrections for typos and
errors in drafts of chapters.
Stuart Reges
University of Washington
Marty Stepp
Stanford University
Allison Obourn
University of Arizona
MyLab Programming
Through the power of practice and immediate personalized
feedback, MyLab Programming™ helps students master
programming fundamentals and build computational thinking skills.
PROGRAMMING PRACTICE
With MyLab Programming, your students will gain first-hand
programming experience in an interactive online environment.
IMMEDIATE, PERSONALIZED
FEEDBACK
MyLab Programming automatically detects errors in the logic and
syntax of their code submission and offers trageted hints that
enables students to figure out what went wrong and why.
GRADUATED COMPLEXITY
MyLab Programming breaks down programming concepts into short,
understandable sequences of exercises. Within each sequence the
level and sophistication of the exercises increase gradually but
steadily.
DYNAMIC ROSTER
Students’ submissions are stored in a roster that indicates whether
the submission is correct, how many attempts were made, and the
actual code submissions from each attempt.
PEARSON eTEXT
The Pearson eText gives students access to their textbook anytime,
anywhere
STEP-BY-STEP VIDEONOTE
TUTORIALS
These step-by-step video tutorials enhance the programming
concepts presented in select Pearson textbooks.
Copyright © 2018 Pearson Education, Inc. or its affiliate(s). All rights reserved. HELO88173 · 11/15
Brief Contents
Chapter 1 Introduction to Python Programming 1
Why Python? 7
Escape Sequences 16
Flow of Control 31
Expressions 59
Literals 62
Arithmetic Operators 62
Precedence 66
2.2 Variables 70
A Program with Variables 74
Increment/Decrement Operators 79
Pseudocode 103
Constants 108
Colors 179
Images 188
Now was repeated the sad ceremonial of two years ago, when my
husband’s body was committed to the flames. Only two years and
the Ideal Ruler and the Child of Promise had both vanished from our
eyes. Surely we shall never understand the workings of Divine
Providence. All that our sad souls can do is to trust in the infinite
wisdom of God.
The blank his loss has left in my life will always be there, but he
must have gone to do a greater work, and the thought of this is the
only thing that gives me comfort.
Countless were the telegrams and letters of sympathy I received,
and the kindness of all my friends touched me very much. The late
Duchess of Connaught sent word from Bagshot: “We all deeply
sympathise with you in your great loss. We look back with pleasure
to the time when Rajey used to stay with us.”
We sent the ashes of our beloved back to Cooch Behar, and they
rest beside those of his father in the marble mausoleum which has
been built in the rose garden. This old garden is a peaceful spot.
Long ago the Maharajah learned his lessons in the ruined summer-
house which still stands on the borders of the lake, where in bygone
times the Maharanis used to bathe, and many legends are connected
with the place. The scented stillness is now unbroken save for the
music of the birds, and the mournful whisperings of the trees when
the wind speaks to them of the sleepers.
This rose garden is walled in on three sides, and from it can be
seen the snow hills far away. There are masses of roses and lilies,
and it is impossible to describe the fragrance of the flowers. Rajey
and his father are surrounded by Peace. Prayers are offered there
every evening, and sometimes the boys go there alone in the
moonlight.
My love is so strong that I think Death has opened the door of
Eternity a little way for me, and my dear ones are nearer to me than
ever. Long ago I saw the roses of youth blooming at Belghuria. Later,
the crimson flowers of love were mine, but the sweetest of all
flowers to me are those of remembrance, which shed their petals
year after year over the ashes of my dear ones who wait for me on
the radiant shore.
Lord Lytton knew me as a little girl in India, but we did not meet
again until 1887 when I was visiting England. I went with my
husband to the Foreign Office party one evening. It was a grand
affair and I had a very nice dress. We were all standing in a line
waiting for the Royal procession to pass when Lord Lytton saw me.
He came and stood by me and putting his arm round my waist said:
“You have grown, and look so pretty, but so grown-up.” I felt very
uncomfortable and kept on saying: “Oh, Lord Lytton, but I am so
old. Do you know I am the mother of three children? Do please
remember that I am an old woman, over twenty.” In his kind voice
he said: “It was only the other day I saw you at your father’s school,
a little, little girl.”
Lord and Lady Ripon were very kind to us. In his time the Ilbert
Bill was passed, which made a great sensation in India and the
English spoke against the Indians and Lord Ripon. One English lady
said to me: “Why was such a man as Lord Ripon sent out to India?
he goes against his Queen.” I am sure the lady did not know what
she was saying, as Lord Ripon was a friend to India and thus served
Her Majesty the late Queen well. When my darling little Rajey had
typhoid fever in Simla in 1882 both Lord and Lady Ripon constantly
made kind inquiries and offered their doctor Anderson, a clever and
charming man.
Lord Dufferin is supposed to have been the cleverest Viceroy in
India; I was so ignorant about politics I cannot say much about his
administrative work, but I do know that he was a very kind personal
friend of mine. Lady Dufferin was the most clever and capable
Vicereine that has ever been out in India. She once came to one of
my “sari” dinners, when we all wore saris, sat on the floor, and ate
with our fingers. One of the A.D.C.s remarked that Her Excellency
looked like a goddess.
Lady Dufferin wrote a book on India in which she said a great deal
about my dear mother, whom she greatly admired. I think she was
amazed to see how cheerfully mother gave up all the comforts of life
after she lost my father. Lady Dufferin showed the greatest interest
in all my father’s institutions, and we were very proud when Lord
Dufferin presented a medal to the Victoria College. Lady Dufferin
founded the Delhi Hospital, where Indian women are trained to be
doctors and midwives. When Lady Dufferin asked me about it and if
it would be a success, I said, “Yes,” but did not quite understand
about it or realise the difficulties. It is difficult to make my Western
sisters understand about caste prejudice in my country. When Lady
Dufferin first began this training much discussion went on all over
India. To begin with, women of high caste could not do work of the
kind as they thought it lowered their position; secondly, zenana
ladies, however poor, did not wish to be trained or study with men,
therefore in the beginning only very common women took up the
medical profession, but now many advanced women have taken it
up and have studied hard and taken degrees, thus serving their
country, for which we owe much gratitude to Lady Dufferin. Lady
Wenlock told me not long ago that the idea was originally Lady
Ripon’s, but she was unable to carry it out before she left India.
Lord and Lady Lansdowne were the greatest Viceroy friends we
ever had. We all, the whole family, loved and admired them and
their children. The Maharajah was treated as a personal friend of
theirs, which made the other Maharajahs very jealous. When I was
very ill once, Lady Lansdowne used to come and see me, and they
were most kind to Rajey. Once H.H. the Begum of Bhopal gave a
strict purdah party and I was invited to meet Lady Lansdowne. I do
not quite remember, but I think the Resident wanted to know who
should sit in the next highest seat to Lady Lansdowne, and he was
informed that I was to sit next to the Viceroy’s wife, which the
Resident did not like at all. When I heard of this I thought I would
not go, but kind Lady Lansdowne on being informed of it sent I do
not know what message to the Begum’s official. Anyway the whole
tone of the letters changed, I was begged to go, and on my arrival
at the party I found that H.H. the Begum had placed Lady
Lansdowne in a chair on her right hand and I was to sit in a chair on
her left hand; these were the only seats, all the other guests came
and shook hands with the Begum while we were seated.
Lady Lansdowne was kindness itself to my children. She never
made any distinction between English and Indians at her parties,
and her tactful consideration made her very popular. I think her
charming mind was reflected in her beautiful face.
I was at my happiest in Lord Lansdowne’s reign; everything
seemed to be so bright in my life at that time, and I often think now
of that happy past. Lord Lansdowne once said: “My house is not half
large enough to hold all the people you and the Maharajah entertain
in camp.” I did appreciate those kind words.
Lord Elgin was a kind Viceroy; I don’t know whether he did much
as a statesman, but he was a very kind easy-going man. Lady Elgin
gave some very cheery children’s parties. At one of these my Jit kept
on having so much ice cream that I am sure all the A.D.C.s and
servants must have longed for us to leave the table. I went to
Calcutta once for a few hours, the Viceroy heard of it and asked me
if I would dine with them quietly; it was no party, only a family
gathering. This was a great honour. I did not think I could have a
maid with me, so I sent for a hair-dresser. He was told not to be
long, but perhaps he felt artistic that evening, for he went on
making curls and waves and using hundreds of hairpins. I was most
impatient and kept reminding him of the time, but it had no effect.
The consequence was that I was about half an hour late, a thing I
shall never forget. When I arrived, I found the two A.D.C.s in
despair, sitting on the steps watching the gate. One of them was the
late Captain Adams. I did not know how to make my excuses and
had to tell the unpleasant truth, that it was the fault of the hair-
dresser, but all they did was to pay nice compliments. I was so
nervous when I went up into the drawing-room that I felt like
running away, but when Lord and Lady Elgin came in and I made my
apologies, Lord Elgin said: “Please don’t be sorry; I am grateful to
you for being a little late. You know it is the English mail day, and
you gave me a little extra time to write a few more letters, for which
I have to thank you.” This made me forget all my troubles and only
remember what a proud and happy woman I was.
There was much splendour in the time of the Curzons, but I don’t
believe that Lord Curzon was ever really in sympathy with us. He is a
very clever man; but, may I be forgiven for my frankness, I found
him slightly interfering in private matters. He was too
unapproachable, which was most regrettable. I consider that he
missed many golden opportunities. Lady Curzon was handsome and
charming, but to my great disappointment I had neither the pleasure
nor the honour of knowing her well.
Lord Curzon did a lot of good to the country; and tried to revive
the old industries, the saris, cashmeres, etc. Also he put up tablets
on great men’s birth places and homes, which was much
appreciated; but he interfered with the future of the Indian Princes’
young sons. Whether the fathers were willing or not he did not wait
to find out, but forced them to send their boys into the Cadet Corps,
and by so doing many boys lost their opportunities of learning
administrative work. Of course, we had to submit because no one
wishes to be in the Viceroy’s bad books.
Photo: Johnston & Hoffmann.
WOODLANDS.
Lord and Lady Minto we admired and liked very much. Lord Minto
was so kind a friend that although he was Viceroy he helped a
zemindar at the cost of much trouble to himself. Lady Minto was the
first to ask the purdah ladies to Government House. She gave parties
for them regularly every year while she was in Calcutta and the
ladies enjoyed them enormously. I remember a Hindu lady
remarking of Lady Minto: “I do like her smile so.” My sister and the
Maharani of Burdwan and I joined together and gave three parties to
Lady Minto at Woodlands, and I got up some tableaux which both
the English and Indian ladies enjoyed. On one occasion I dressed
Lady Minto in a Bengali bridal dress, scarlet and gold, and she
looked lovely. Lady Minto told me afterwards that when she returned
to Government House she sent a message to the military secretary
that a Maharani was waiting in the hall, and when he came and
found Lady Minto in the bridal dress for a moment he thought it
really was a Maharani.
I remember a Bengali gentleman of high position telling us once:
“Lord Minto is a thorough gentleman; when I and my friend went to
call on him he was so nice and made us feel quite at home. What
struck us most was that at the close of the visit, when we were
going away, Lord Minto, instead of calling an orderly or an A.D.C.,
walked up to the door and opened it himself. We felt uncomfortable,
but it was a gentlemanly action; by opening the door he lost
nothing, and we gained so much.”
I feel it my duty to allude to something that happened in Lord
Minto’s reign. A rumour was circulated that a most loyal British
subject was disloyal to the Government. I was horrified when I
heard the lie; it reached the highest circles. Even Sir O’Moore
Creagh, then Commander-in-Chief, may have credited it. Perhaps it
was some fellow-countryman who started this unpardonable lie; but
how could the Government believe such an impossible thing? I only
hope that whoever did this great wrong will confess his wickedness
before he leaves this world.
Lord Hardinge did a lot of good to many people, but he was never
very kindly disposed to the Cooch Behar Raj family. Soon after I lost
my husband we came back to India, and as I had received nothing
but kindness from the Royal Family and from so many Viceroys, I
expected that Lord Hardinge as Viceroy would be kind to me. But on
the contrary he did not seem to take any trouble to be kind to my
son. When our present King was at the Delhi Durbar Lord Hardinge
paid many visits to the other Maharajahs, but never thought of
leaving his card on the Maharajah of Cooch Behar, which was not
only an insult to the Maharajah but to the whole of Bengal. Lord
Hardinge also interfered with our private affairs, at which I was
surprised because we liked him and thought him clever and never
opposed him.
Here I might mention that at this Delhi Durbar a certain Political
Officer visited the Maharajah’s camp in ordinary lounge clothes, a
thing which even H.M. the King would not think of doing. Such
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
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.
textbookfull.com