#๐Ÿ”’ Help with lists

10 messages ยท Page 1 of 1 (latest)

half salmon
#

Hello! I need to develop a function to detect collision between one spaceship (given like [ [position x; position y], velocity, radius]) and an undefined number of stars ([position x; position y], mass, radius]]) as part of a homework. Each one of them has a radius and a center, I wrote like this:

def collisiondetection(Spaceship, Stars):
SpaceshipInitialPlace = Spaceship[0]
RadiusSpaceship = Spaceship[2]
Collision = false
for Star in Stars:
StarPosition = Star[0]
StarRadius = Star[2]
if distance*(StarPosition, SpaceshipInitialPlace) <= RadiusSpaceship + StarRadius:
Collision - true
return (Collision)

However, it stops when I give a list with more than one star, like collisiondetection([[-800, 0], [9, 4], 70], [[[0, 0], 8e+22, 10], [[-900, 10], 5e+21, 60]]), it only reads the first star, while I need it to read all of them.

Thanks!

*I've previously defined distance and it works

plush treeBOT
#

@half salmon

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

half salmon
#

In this case, the first star doesn't collide, but the second one does

#

However, it stops in the first star and doesn't read the second

#

oh, I found the error

#

The "return" was inside the loop "for"

#

Thank you, guys, anyway!

#

!close

plush treeBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.