Pammer the Spammer

Level pending

Pammer was his usual self, all in his pajamas, late up at 1 am. He was playing AoPS's For The Win! game. He created a spammer function as follows:

def spam(n):
    for i in range(1,n):
        print("/away")

Assume that the /away function makes the player invisible in-game.

Which of the following statements are true?

1) The player will be invisible when you input an even number.

2) The player will not be invisible when you input an even number

3) The function will output an error once called.

4) The function will not do anything once called.

2 3 4 1

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

1 solution

Kevin Mo
Jan 16, 2014

This program, spam(), takes in one argument, n . You can go either way to solve this:

The Cheat Way

Input the program into a Python interpreter. A good Python interpreter is CodeSkulptor , which is online. Whatever you choose, input the code above to your interpreter and call the command with

1) an even number greater than 0, preferred number range is 2-8

2) an odd number greater than 1, preferred number range is 3-7

IMPORTANT: MAKE SURE YOU CALL THEM SEPARATELY

If you call the command, the /away function will run an even number of times if you input an odd number greater than 1. If you call the command, the /away function will run an odd number of times if you input an number number greater than 0.

Thus, you can conclude that by running an odd number of times will run the 'away' function, while having an even number won't run it. Thus the answer 1 ) \boxed{1) } The player will be invisible when you input an even number.

The Logical Way

Ok, so you don't want to cheat. No worries; this problem can be solved just by looking at it. Try inputting the number '2' for n. The for function will run once because of for i in range(1,2) . The 'away' function will be run once, thus activating the player's invisibility. Thus the answer 1 ) \boxed{1) } The player will be invisible when you input an even number.

If you have any questions or comments about this problem and the answer, feel free to comment below. I am more than happy to accept your suggestions/comments/concerns/questions.

You probably should have specified that the /away function is a toggle. Also that the player starts out visible.

Steven Perkins - 7 years, 1 month ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...