Need Help With Ghost Gobble Arcade Game Task 4 Test # 10 :((

Bruhhhh. I need help with Test #10. #10 keeps telling me that if you’ve eaten all the dots, but get touched by the ghost you lose. I’ve tried doing that but I keep getting it wrong. Everything else is correct. Also, when I make changes, the results start changing and I get different tests wrong :((.

My code:


def eat_ghost(power_pellet_active, touching_ghost):
    """Verify that Pac-Man can eat a ghost if he is empowered by a power pellet.

    :param power_pellet_active: bool - does the player have an active power pellet?
    :param touching_ghost: bool - is the player touching a ghost?
    :return: bool - can the ghost be eaten?
    """
    if power_pellet_active and touching_ghost:
        return True
    else:
        return False

def score(touching_power_pellet, touching_dot):
    """Verify that Pac-Man has scored when a power pellet or dot has been eaten.

    :param touching_power_pellet: bool - is the player touching a power pellet?
    :param touching_dot: bool - is the player touching a dot?
    :return: bool - has the player scored or not?
    """

    if touching_power_pellet or touching_dot:        
        return True
    else:
        return False


def lose(power_pellet_active, touching_ghost):
    """Trigger the game loop to end (GAME OVER) when Pac-Man touches a ghost without his power pellet.

    :param power_pellet_active: bool - does the player have an active power pellet?
    :param touching_ghost: bool - is the player touching a ghost?
    :return: bool - has the player lost the game?
    """

    if touching_ghost and not power_pellet_active:
        return True
    else:
        power_peller_active = True
        return False
def win(has_eaten_all_dots, power_pellet_active, touching_ghost):
    """Trigger the victory event when all dots have been eaten.

    :param has_eaten_all_dots: bool - has the player "eaten" all the dots?
    :param power_pellet_active: bool - does the player have an active power pellet?
    :param touching_ghost: bool - is the player touching a ghost?
    :return: bool - has the player won the game?
    """

    if has_eaten_all_dots:
        return True
    if not has_eaten_all_dots:
        return False
    if power_pellet_active and touching_ghost:
        return True
    if not power_pellet_active and touching_ghost:
        return False
    if has_eaten_all_dots and touching_ghost: # test 10 :(
        return False
        

Please help again :frowning:

There are women here, too!

Could you share the test which is running and the error output? That would highlight what function is being called, with what values and what is expected back.

That allows you and us to look at your code, figure out which function is running and with what values and compare what it actually does vs what is it supposed to return.

@IsaacG Test #10 is running :D.

Also thank you so much for always answering my questions :D.
You’re so nice :3

Screenshot from 2023-12-14 21-30-14

In the future, please use codeblocks and not images :slight_smile:

Do you see that the test calls this function?

win(has_eaten_all_dots=True, power_pellet_active=False, touching_ghost=True)

The test expects to get back False because Pacman is touching a ghost so Pacman loses. Do you understand why it ought to be False?

Looking at your code, when called with those values, do you see why/where it returns True instead?

1 Like

Since Pacman is touching a ghost, the test anticipates returning False, which means Pacman loses. Can you see why that should be False? geometry dash lite
Have a look at your code and see where/why it returns True instead of false when run with those values?

2 Likes

@IsaacG @mittensyielding

I see now!!! I got it! I realize now that because I made the has_eaten_all_dots variable true at the start, I was accidentally making every other argument true as a result. Thank you guys :3!!!

def win(has_eaten_all_dots, power_pellet_active, touching_ghost):
    """Trigger the victory event when all dots have been eaten.

    :param has_eaten_all_dots: bool - has the player "eaten" all the dots?
    :param power_pellet_active: bool - does the player have an active power pellet?
    :param touching_ghost: bool - is the player touching a ghost?
    :return: bool - has the player won the game?
    """

    if not has_eaten_all_dots:
        return False
    if power_pellet_active and touching_ghost:
        return True
    if not power_pellet_active and touching_ghost:
        return False
    if has_eaten_all_dots and touching_ghost: # test 10 :D
        return False
    if has_eaten_all_dots:
        return True

I don’t know how to make both the solution :(

What tests are failing are failing now? What inputs? Which line of code is returning the wrong result?

Oh I meant that I didn’t know how to make you guy’s responses the solution bc you both helped :smiley:

I’m also having this problem. Everything is working except for Task 4# 10 and when I make changes I get more errors.

def eat_ghost(power_pellet_active, touching_a_ghost):

if power_pellet_active == True and touching_a_ghost == True:
   return True
else:
    return False

power_pellet_active = True
touching_a_ghost = True

var_1=eat_ghost(power_pellet_active, touching_a_ghost)
print(var_1)

def score(touching_pellet, touching_dot):

if touching_pellet == True or touching_dot == True:
    return True
else:
    return False

touching_pellet = True
touching_dot = True

stored_score=score(touching_pellet, touching_dot)
print(stored_score)

def lose(power_pellet_active, touching_a_ghost):

if power_pellet_active == False and touching_a_ghost == True: 
    return True
else: 
    return False

result= lose(power_pellet_active, touching_a_ghost)
print(result)

def win(all_dots_eaten, power_pellet_active, touching_a_ghost):

if all_dots_eaten == True and stored_score == True and var_1 == True and result is not True:
    return True

else: 
    return False 

touching_ghost = False
all_dots_eaten = False

Pac_Man_Wins = win(all_dots_eaten, power_pellet_active, touching_a_ghost)
print(Pac_Man_Wins)

We can’t tell what is wrong with your code without seeing your code and errors! Also, this thread is 3 months old :slight_smile: In general, try to avoid resuscitating dead threads.

If you’d like help, please provide details. See How to ask for help with your code online | Angelika.me to see what a good question ought to look like.