JacobTomaw

JacobTomaw

Python Brain Teasers: Teaser 3 wrong answer

For every minor version of Python 3 I can run the code against quickly this code prints 6.

❯ for minor in `seq 2 8`; do; echo "Python 3.$minor"
docker run -it python:3.$minor python -c "print(len('Kraków'))"
done
Python 3.2
6
Python 3.3
6
Python 3.4
6
Python 3.5
6
Python 3.6
6
Python 3.7
6
Python 3.8
6

Python 2.7 the answer is 7.
Am I doing something unexpected?

Most Liked

JacobTomaw

JacobTomaw

I did not doubt that you have tested the code.
Your file definitely has different chars in it. Below the file /tmp/krakow has your string on the first line and mine that I typed on my Mac. Yours is o + Combining Acute Accent and mine is Latin Small Letter O with Acute. If I needed to I am sure I could figure out how to type combining acute accent, but when working through the book and seeing a char i can type with two keystrokes on my mac (option + e, o) I am going to do that. It might be valuable to note this in the book in someway.

❯ more /tmp/krakow
Kraków
Kraków

❯ xxd -b -c9 /tmp/krakow
00000000: 01001011 01110010 01100001 01101011 01101111 11001100 10000001 01110111 00001010  Krako..w.
00000009: 01001011 01110010 01100001 01101011 11000011 10110011 01110111 00001010           Krak..w.

❯ xxd  -c9 /tmp/krakow
00000000: 4b72 616b 6fcc 8177 0a  Krako..w.
00000009: 4b72 616b c3b3 770a     Krak..w.
tebeka

tebeka

Author of Go Brain Teasers

Hi @JacobTomaw. It’s probably a problem in the encoding of the PDF (trust me, I tried :slight_smile: )
Take a look at the code in https://github.com/tebeka/python-brain-teasers and let me know if you have an issue - it prints 7 for me:

$ python --version
Python 3.8.3
$ python city.py  
7
tebeka

tebeka

Author of Go Brain Teasers

I do doubt myself :slight_smile:

I’ll think how to clarify this in the book. Thanks!

Popular Prag Prog topics Top

jimschubert
In Chapter 3, the source for index introduces Config on page 31, followed by more code including tests; Config isn’t introduced until pag...
New
johnp
Running the examples in chapter 5 c under pytest 5.4.1 causes an AttributeError: ‘module’ object has no attribute ‘config’. In particula...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New
Chrichton
Dear Sophie. I tried to do the “Authorization” exercise and have two questions: When trying to plug in an email-service, I found the ...
New
swlaschin
The book has the same “Problem space/Solution space” diagram on page 18 as is on page 17. The correct Problem/Solution space diagrams ar...
New
curtosis
Running mix deps.get in the sensor_hub directory fails with the following error: ** (Mix) No SSH public keys found in ~/.ssh. An ssh aut...
New
hazardco
On page 78 the following code appears: <%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
a.zampa
@mfazio23 I’m following the indications of the book and arriver ad chapter 10, but the app cannot be compiled due to an error in the Bas...
New

Other popular topics Top

DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
Exadra37
On modern versions of macOS, you simply can’t power on your computer, launch a text editor or eBook reader, and write or read, without a ...
New
AstonJ
This looks like a stunning keycap set :orange_heart: A LEGENDARY KEYBOARD LIVES ON When you bought an Apple Macintosh computer in the e...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
PragmaticBookshelf
Author Spotlight: Karl Stolley @karlstolley Logic! Rhetoric! Prag! Wow, what a combination. In this spotlight, we sit down with Karl ...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New
PragmaticBookshelf
Author Spotlight: Tammy Coron @Paradox927 Gaming, and writing games in particular, is about passion, vision, experience, and immersio...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New
PragmaticBookshelf
Author Spotlight: Bruce Tate @redrapids Programming languages always emerge out of need, and if that’s not always true, they’re defin...
New
New

Latest in PragProg

View all threads ❯