Git Product home page Git Product logo

Comments (6)

csev avatar csev commented on July 18, 2024

Thanks. All set.

from py4e.

jtspinks avatar jtspinks commented on July 18, 2024

In the text, fruit refers to the variable fruit, which was set to the string literal 'banana'. If the above changes are to be implemented, then the len() function should be passed the string literal 'fruit' and not the variable fruit.

I forked the repo, and submitted the correction back to the variable fruit (i.e. 'banana').

(pdf pg 68 of text, section 6.2 Getting the length of a string using len; Original text version with typos in bold)
len is a built-in function that returns the number of characters in a string:

>>> fruit = 'banana'
>>> len(fruit)
6

To get the last letter of a string, you might be tempted to try something like this:

>>> length = len(fruit)
>>> last = fruit[length]
IndexError: string index out of range

The reason for the IndexError is that there is no letter in β€œfruit” with the index 5. Since we started counting at zero, the six letters are numbered 0 to 4. To get the last character, you have to subtract 1 from length:

(pdf pg 68 of text, section 6.2 Getting the length of a string using len; Corrected version)
len is a built-in function that returns the number of characters in a string:

>>> fruit = banana
>>> len(fruit)
6

To get the last letter of a string, you might be tempted to try something like this:

>>> length = len(fruit)
>>> last = fruit[length]
IndexError: string index out of range

The reason for the IndexError is that there is no letter in fruit with the index 6. Since we started counting at zero, the six letters are numbered 0 to 5. To get the last character, you have to subtract 1 from length:

from py4e.

MikePfunk28 avatar MikePfunk28 commented on July 18, 2024

Yes I read that wrong, I was isolating the problem when I was working on it, thinking it did not carry. After reading your comment it makes sense, thanks!. I wonder if this has been corrected because my version is showing the incorrect version.

from py4e.

MikePfunk28 avatar MikePfunk28 commented on July 18, 2024

Is this fixed? Or maybe the update has not been committed yet? In my version it has the incorrect information, like you pointed out jtspinks, did this get updated, is your version off as well? Good thing you caught that, I was working on a problem and thinking to myself, I messed this up somewhere. I think this was it, I reopened for reference.

from py4e.

jtspinks avatar jtspinks commented on July 18, 2024

I corrected it and submitted the PR. I think it just has not updated yet.

from py4e.

csev avatar csev commented on July 18, 2024

So this got merged into github pretty quickly - the English PDF online updates every 30 minutes. But the HTML on www.py4e.com takes a manual step by me - which I have now done. So it should be right in all of my copies except the actual print book on Amazon which I update about once per year. Let me know if there is a copy where this fix is not yet represented.

from py4e.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.