# Fizz buzz help with modulo

**URL:** <https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506>\
**Category:** Ambassador\
**Created:** [November 20, 2018, 12:09pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506 "2018-11-20T12:09:07Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mratranslate](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mratranslate](https://discourse.codecombat.com/u/mratranslate)\
**Post date:** [November 20, 2018, 12:09pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/1 "2018-11-20T12:09:08Z")

</div>

```python
# Be aware of hidden traps, and count your steps
# Coins are separated by 10 meters distance

steps = 1

while True:
    # If the number of steps is divisible by 3 AND by 5 -- move to North-West
    if steps % 3 and 5 == 0:
            hero.moveXY(hero.pos.x - 10, hero.pos.y + 10)
    # Else if the number of steps is divisible by 3 -- move to East
    else:
        if steps % 3 == 0:
            hero.moveXY(hero.pos.x + 10, hero.pos.y)
    # Else if the number of steps is divisible by 5 -- move to West
        else:
            if steps % 5 == 0:
                hero.moveXY(hero.pos.x - 10, hero.pos.y)
            else:
                hero.moveXY(hero.pos.x, hero.pos.y + 10)
    
    steps += 1

```

Thought I’d got this one, but seem to be getting blown up on step 15?

---

<div class="post-metadata">

**Author:** ![Unknown](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/unknown/32/9352_2.png) [@Unknown](https://discourse.codecombat.com/u/Unknown)\
**Post date:** [November 20, 2018, 2:49pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/2 "2018-11-20T14:49:16Z")

</div>

What is step 15?

> [@mratranslate](#):
>
> ```python
> if steps % 3 and 5 == 0:
> 
> ```

Try

```python
if steps % 3 and % 5 == 0:

```

I don’t know if thats the problem but you can try it.

---

<div class="post-metadata">

**Author:** ![mratranslate](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mratranslate](https://discourse.codecombat.com/u/mratranslate)\
**Post date:** [November 20, 2018, 3:54pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/3 "2018-11-20T15:54:27Z")

</div>

No this does not help - in fact this yields an instant code error sorry.

---

<div class="post-metadata">

**Author:** ![Unknown](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/unknown/32/9352_2.png) [@Unknown](https://discourse.codecombat.com/u/Unknown)\
**Post date:** [November 20, 2018, 3:56pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/4 "2018-11-20T15:56:14Z")

</div>

Oh well sorry I don’t code python 😵 🔨, but what is is step 15?

---

<div class="post-metadata">

**Author:** ![mratranslate](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mratranslate](https://discourse.codecombat.com/u/mratranslate)\
**Post date:** [November 20, 2018, 4:00pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/5 "2018-11-20T16:00:40Z")

</div>

Then why are you responding on a python forum…?!? step refers simply to how many steps the hero has taken.

---

<div class="post-metadata">

**Author:** ![Unknown](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/unknown/32/9352_2.png) [@Unknown](https://discourse.codecombat.com/u/Unknown)\
**Post date:** [November 20, 2018, 4:01pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/6 "2018-11-20T16:01:40Z")

</div>

Ok sorry i’m just trying to help

---

<div class="post-metadata">

**Author:** ![Unknown](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/unknown/32/9352_2.png) [@Unknown](https://discourse.codecombat.com/u/Unknown)\
**Post date:** [November 20, 2018, 4:05pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/7 "2018-11-20T16:05:58Z")

</div>

Maybe @Deadpool198 or @MunkeyShynes can help.

---

<div class="post-metadata">

**Author:** ![MunkeyShynes](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/munkeyshynes/32/9277_2.png) [@MunkeyShynes](https://discourse.codecombat.com/u/MunkeyShynes)\
**Post date:** [November 20, 2018, 4:58pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/8 "2018-11-20T16:58:02Z")

</div>

> [@Unknown](#):
>
> ```python
> if steps % 3 and % 5 == 0:
> 
> ```

This is on the right track but not complete. Think about what that statement is really saying. Remember that computers are very literal and kinda stupid. They lack the ability to figure out what you mean. You have to be very precise. It should be:

```python
if steps % 3 == 0 and steps % 5 == 0:

```

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [November 21, 2018, 7:21am UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/9 "2018-11-21T07:21:33Z")

</div>

I always wish there was a function which let you do that, like:

```python
if enemy.type == "ogre" or "munchkin" or "thrower":
    hero.attack(enemy)
#but it has to make it twice as frickin long. (I run into this a lot, especially with a findEnemyHero function)
if enemy.type == "ogre" or enemy.type == "munchkin" or enemy.type == "thrower":

```

Anyway, just wanted to share my thoughts.  
🦁

---

<div class="post-metadata">

**Author:** ![Chaboi\_3000](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/chaboi_3000/32/48486_2.png) [@Chaboi\_3000](https://discourse.codecombat.com/u/Chaboi_3000)\
**Post date:** [November 21, 2018, 7:34am UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/10 "2018-11-21T07:34:08Z")

</div>

It won’t work with current python logic though. It’s the `or's` that are separating them so it’s like if enemy.type==‘ogre-m’ or ‘munchkin’. The code won’t know what munchkin is unless you assign enemy.type to each one. **I think…**

---

<div class="post-metadata">

**Author:** ![mratranslate](https://avatars.discourse-cdn.com/v4/letter/m/e99b99/32.png) [@mratranslate](https://discourse.codecombat.com/u/mratranslate)\
**Post date:** [November 21, 2018, 3:06pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/11 "2018-11-21T15:06:58Z")

</div>

thanks 🙂

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [November 21, 2018, 9:04pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/12 "2018-11-21T21:04:11Z")

</div>

[How to use \*args and \*\*kwargs in Python](https://www.saltycrane.com/blog/2008/01/how-to-use-args-and-kwargs-in-python/)  
I got your idea and this is my function. It’s not well tested and I will be glad if someone improves it:

```python
def orTypes(unit, *types):
    for type in types:
        if unit and unit.type == type:
            return type
    return False
# possible use
enemy = hero.findNearestEnemy()
if enemy and enemy.health > 0 and orTypes(enemy,'witch', 'thrower'):
    hero.attack(enemy)

```

---

<div class="post-metadata">

**Author:** ![Deadpool198](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/deadpool198/32/16753_2.png) [@Deadpool198](https://discourse.codecombat.com/u/Deadpool198)\
**Post date:** [November 22, 2018, 3:00pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/13 "2018-11-22T15:00:20Z")

</div>

I really like that idea! Thanks, I’ll put it in my code.  
🦁

---

<div class="post-metadata">

**Author:** ![xython](https://sea2.discourse-cdn.com/flex016/user_avatar/discourse.codecombat.com/xython/32/7269_2.png) [@xython](https://discourse.codecombat.com/u/xython)\
**Post date:** [May 2, 2019, 8:47pm UTC](https://discourse.codecombat.com/t/fizz-buzz-help-with-modulo/16506/14 "2019-05-02T20:47:51Z")

</div>

same code in java-script - also not tested  
[The arguments object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/arguments)

```python
function orTypes ( unit){
  var returnValue = false;
  for (var i = 1; i < arguments.length; i++ ){
      // unit is arguments[0]
      var type = arguments[i];
      if (unit && unit.type == type){
        returnValue = true;
        // you can also assign unit or type to returnValue
      }  
  }
  return returnValue;
}
// possible use
var enemy = hero.findNearestEnemy();
if (enemy && enemy.health > 0 && orTypes(enemy,'witch', 'thrower') 
    hero.attack(enemy);

```
