Random module doesn't work as in the exercise


#1

I’m currently reading “Python for Everybody - Exploring Data Using Python 3” by Charles R. Severance.

In the book I’m currently learning about the random module and after replicating the code in pycharm I get a different result than the one in the book and I can’t seem to understand why that is. Could someone help me out please?

Thank you!

Here’s the link so that you can see what’s in the book and what my result is: https://imgur.com/a/V6hYJFM


#2

different code


#3

I’m sorry, but I don’t know what you mean by ‘different code’


#4

It’s different


#5

to me it looks exactly the same as in the book, can you tell me what is different?


#6

It’s very short, I trust you can compare. Worst case you have to compare each character one at a time. There still aren’t many.

You can also look at the output and consider where it could at all be getting that information from.


#7

Only after I copied it I realized the x :man_facepalming: thanks!


#8

Note that you just made a great argument for not using single-letter variable names.

If the bug is telling an outright lie you may be able to tell without looking at any of the rest just because of the names.

# eh. doesn't seem right.
these_here_kittens.murder_the_whole_bunch()

# eh. I don't see anything wrong here.
thing.stuff()

i is rather common to mean something like index or iteration though.
and in extremely small (probably less than 5-10 lines to make up numbers) amounts of code I wouldn’t complain, one is supposed to be able to eyeball that, or reason it out


#9

That’s true, I’m trying to put a meaning to the names of my variables, this time was trying to quickly test what was in the book, obviously making a mistake.