B
19

My Python script printed a list of numbers that were all the same, even though I wrote a loop to make them different.

I wrote a for loop in Python to create a list of 10 random numbers between 1 and 100, but it just printed the number 42 ten times. I learned I needed to import the random module before using random.randint. Does anyone know other common beginner mistakes with Python's random functions?
3 comments

Log in to join the discussion

Log In
3 Comments
phoenixb34
phoenixb342mo ago
Remember my buddy who kept getting the same "random" password every time? He forgot to call the function, just used the function name, so it reused the first result. That kind of thing can really trip you up.
1
smith.anna
smith.anna2mo agoProlific Poster
My first Python script did that exact same thing with the number 17.
0
claire_hart53
It's wild how often 17 pops up. My old car's license plate ended in it, my first apartment was number 17, and it's always the default number I punch in for a PIN guess. Feels like one of those numbers that just follows people around for no real reason.
6