Having issue figuring out how to start this problem.

Page 1 of 1

3 Replies - 1965 Views - Last Post: 09 September 2014 - 07:05 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'https://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=353419&amp;s=286557739e3f56de5ab12e6899c234b9&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

#1 brandon916

Reputation: 0
• Posts: 13
• Joined: 07-September 14

Having issue figuring out how to start this problem.

Posted 09 September 2014 - 06:19 PM

Im having issues with this problem. I know I need to approach it using higher order functions but I just figure out how to start it. I know I need to a create a new function for the range.The question is: Write a function that takes in a number n and returns a function that takes in a number range which will print all numbers from 0 to range (including 0 but excluding range) but print Buzz! instead for all the numbers that are divisible by n.

```def make_buzzer(n):
""" Returns a function that prints numbers in a specified
range except those divisible by n.

>>> i_hate_fives = make_buzzer(5)
>>> i_hate_fives(10)
Buzz!
1
2
3
4
Buzz!
6
7
8
9
"""

```

Is This A Good Question/Topic? 0

Replies To: Having issue figuring out how to start this problem.

#2 jon.kiparsky

• Beginner

Reputation: 11073
• Posts: 18,911
• Joined: 19-March 11

Re: Having issue figuring out how to start this problem.

Posted 09 September 2014 - 06:24 PM

Okay, so maybe start with a simpler problem. Write me a function f that returns a function fprime, such that fprime returns the word "chicken".

#3 brandon916

Reputation: 0
• Posts: 13
• Joined: 07-September 14

Re: Having issue figuring out how to start this problem.

Posted 09 September 2014 - 06:52 PM

def fprime():
return "chicken"
def f():

re

oops disregard that i wasnt finished

```def fprime():
return "chicken"
def f():
return fprime()

```

#4 jon.kiparsky

• Beginner

Reputation: 11073
• Posts: 18,911
• Joined: 19-March 11

Re: Having issue figuring out how to start this problem.

Posted 09 September 2014 - 07:05 PM

Okay, you could do that. You could also do it this way:

```>>> def f():
...     def fprime():
...             return 'chicken'
...     return fprime
...

```

Obviously, this works:

```>>> f()
<function f.<locals>.fprime at 0x10e222680>
>>> f()()
'chicken'
>>> g = f()
>>> g()
'chicken'
>>>
```

So now let's try making f so that f takes a string, and returns fprime() that returns that string when called.

And when you've done that, define an f taking a string s and returning fprime which takes a string sprime and returns the concatentation of s and sprime.

That might put you in a position to address your original question.