Prime Pathing PLZ help... [Python]

so it should be 7AM… whatever lets just focus.

1 Like

You can find if the number is a prime number by using the simple modulo function.
I advise you create a function called checkIfPrime(number).
First, you’d have to check if the number is greater than 1. So since checkIfPrime() returns a True or a False, you’d check to see if it’s less than or equal to 1. (Use number <= 1), and return False if that’s the case. Otherwise, iterate through all cases using the element n and range 2 and the number. Then use the modulo(%) to check if diving the number with the element n returns 0 or not. (aka. if it’s divisible perfectly by another number that isn’t 1 or itself). If there is a number, then return False, else, that means our number is a prime, so return True.

1 Like

But this means number less than or equal to 1

Mumbo_6

1 Like

I think it says pretty clearly…

Like this?

def checkIfPrime(number):
    if number <= 1:
        return false
    elif number % i == 0:
        return true

Sorry it took me a while,
Mumbo_6

1 Like


Now it gives me this thing.

Mumbo_6

1 Like

You forgot the whole step ^^^

1 Like

sorry, it says “i is not defined”

1 Like

How do I do that?

Mumbo_6

1 Like

Remember for loops? Use those.

2 Likes

is this how you mean? Sorry if I make you annoyed by how stupid I am. (I really am :smile:)

def checkIfPrime(number):
    if number <= 1:
        return false
    for n in range:
        return true

Mumbo_6

1 Like

Screenshot 2020-09-19 at 08.42.11
Now theres this error in my way

1 Like

You’re getting close, but you forgot to specify the range. I’ve stated it up here ^^^
Also make sure to capitalize true and false for python

2 Likes

if I put for n in range 2: it says I cannot put a number after range. Also, how do I define range?

Mumbo_6

1 Like

for n in range(x,y). In this case, you’d use this:

1 Like

what is the number? it still does not work if I put: for n in range 2 n:

1 Like

The number is the value of your mine.

2 Likes

but how do I write the number of the mine? This function is the first function in my code.

def checkIfPrime(number):
    if number <= 1:
        return False
    for n in range 2:
        return True

friends = hero.findFriends()
mines = hero.findHazards()
firstMines = []
for mine in mines:
    if mine.pos.y > 30 and mine.pos.x < 80:
        if checkIfPrime(mine.value):
            firstMines.append(mine)
for mine in firstMines:
    if mine.pos.x > (hero.pos.x - 25):
        hero.moveXY(mine.pos.x + 10, mine.pos.y)
        hero.moveXY(mine.pos.x, mine.pos.y)
        hero.moveXY(hero.pos.x - 10, hero.pos.y)
        for friend in friends:
            hero.command(friend, "move", {"x": mine.pos.x + 10, "y": mine.pos.y})
            hero.wait(1.6)
            hero.command(friend, "move", {"x": mine.pos.x, "y": mine.pos.y})
            hero.command(friend, "move", {"x": mine.pos.x - 10, "y": mine.pos.y})
hero.moveXY(2, 15)
for friend in friends:
    hero.command(friend, "move", {"x": 2, "y": 15})


Mumbo_6

2 Likes

Since number is a parameter in the function checkIfPrime(), you can define that number within the function. For example, you wrote checkIfPrime(mine.value):, so calling number in the function checkIfPrime will use the value of the mine(mine.value)

2 Likes

If you mean this:

def checkIfPrime(number):
    if number <= 1:
        return False
    for n in range (mine.value):
        return True

My hero walks into a non-prime trap.

Mumbo_6