Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Hai Phan](https://uploads.teamtreehouse.com/production/profile-photos/9816782/micro_IMG_20180221_232338.jpg)
Hai Phan
2,442 PointsI can't add new monsters, please help!
This is a part of my game that I'm testing out, I want to add a new monster after 3 moves, but I got this error "TypeError: object of type 'NoneType' has no len()". Anyone can help me, please!
import os
import random
SMALL_CELLS = [
(0,0),(1,0),(2,0),(3,0),(4,0),
(0,1),(1,1),(2,1),(3,1),(4,1),
(0,2),(1,2),(2,2),(3,2),(4,2),
(0,3),(1,3),(2,3),(3,3),(4,3),
(0,4),(1,4),(2,4),(3,4),(4,4)
]
ALL_MONSTERS = [(1,1), (2,2), (3,3)]
ALL_MOVES = ["A", "S", "D"]
custom_cells = SMALL_CELLS
player = random.choice(SMALL_CELLS)
def new_monster(custom_cells, player, ALL_MOVES, ALL_MONSTERS):
if custom_cells == SMALL_CELLS:
if len(ALL_MOVES) == 0:
print("** New monster will appear in 3 moves **")
elif len(ALL_MOVES) % 3 == 1:
print("** New monster will appear in 2 moves **")
elif len(ALL_MOVES) % 3 == 2:
print("** New monster will appear in 1 moves **")
elif len(ALL_MOVES) % 3 == 0:
print("** New monster will appear in 3 moves **")
abc = random.choice(custom_cells.copy().remove(player))
ALL_MONSTERS.append(abc)
return ALL_MONSTERS
print(new_monster(custom_cells, player, ALL_MOVES, ALL_MONSTERS))
1 Answer
![KRIS NIKOLAISEN](https://secure.gravatar.com/avatar/65d74a723997b41a80d2d909c6e06960?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
KRIS NIKOLAISEN
54,969 PointsThe remove method doesn't return anything so in your code custom_cells.copy().remove(player) = none. I made the following modification:
elif len(ALL_MOVES) % 3 == 0:
print("** New monster will appear in 3 moves **")
abc = custom_cells.copy()
abc.remove(player)
abc = random.choice(abc)
ALL_MONSTERS.append(abc)
return ALL_MONSTERS
Not sure what this does without seeing the rest of the code.
Hai Phan
2,442 PointsHai Phan
2,442 PointsThanks for the answer, this helps me a lot!![:+1: :+1:](https://image-proxy-cdn.teamtreehouse.com/6d8de85e38fee3161a0f29fbc06cd3701ecdafed/68747470733a2f2f7374617469632e7465616d74726565686f7573652e636f6d2f696d616765732f656d6f6a692f756e69636f64652f31663434642e706e67)