so it should be 7AM… whatever lets just focus.
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.
But this means number less than or equal to 1
Mumbo_6
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
You forgot the whole step ^^^
sorry, it says “i is not defined”
How do I do that?
Mumbo_6
Remember for loops? Use those.
is this how you mean? Sorry if I make you annoyed by how stupid I am. (I really am )
def checkIfPrime(number):
if number <= 1:
return false
for n in range:
return true
Mumbo_6
Now theres this error in my way
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
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
for n in range(x,y)
. In this case, you’d use this:
what is the number? it still does not work if I put: for n in range 2 n:
The number is the value of your mine.
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
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
)
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