Comments (6)
Thanks. All set.
from py4e.
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.
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.
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.
I corrected it and submitted the PR. I think it just has not updated yet.
from py4e.
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)
- SQLite DB graded assignment seems broken HOT 1
- "Using Python on Replit": "Writing Your First Program on Replit" missing some details HOT 1
- Chapter 8/exercise 4:sort and print the list of unique words in alphabetical order HOT 3
- there is no Autograder: Exercise 3.2 HOT 1
- Small typo issue in quiz of chapter 10 HOT 1
- login problem HOT 1
- PY4E.COM LOGOUT ISSUE
- Material Of Python by University Of Michgan HOT 1
- Material of python by UNI of Michgan HOT 1
- Chrome browser issue unsafe http:// URLs HOT 1
- week 6-assignment 4.6 HOT 2
- Math module introduction example in lesson 04-functions results in an error HOT 3
- Chapter 6 error HOT 1
- Chapter selector at the end of the chapter HOT 1
- Weird note formatting talking about Python 2 HOT 3
- π‘ idea: list funciton is not necessary In 10.5 (page 124) HOT 1
- 'format sequence' should be ommited from the glossary of the 6th chapter HOT 1
- Summary of py4e is incorrect HOT 2
- Line 18 in py4e/code3/twtest.py HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from py4e.