Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Python Functional Python The Lambda Lambada Partials

José Arturo González Navarro
José Arturo González Navarro
7,088 Points

Can someone help me with the answers for partial on functional Python, that is all I am missing to finish the course!!

I understood everything else perfectly but partials, I cant do the challenge.

Thank you!

2 Answers

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,426 Points

I suspect your are stuck on Task 2

# Task 1 of 4
# First, import 'partial' from 'functools'.
from functools import partial

prices = [ 10.50, 9.99, 0.25, 1.50, 8.79, 101.25, 8.00]

def discount(price, amount):
    return price - price * (amount/100)

# A 'partial' is a function where some of its input parameters have
# already been defined.

# The function 'discount' has two parameters: 'price' and 'amount'.
# The new function 'discount_10' has one parameter: 'price'.
# The amount is pre-defined using the 'partial' command

# Task 2 of 4
# Now, use 'partial' to make a version of 'discount' that applies
# a 10% discount. Name this partial function 'discount_10'.
discount_10 = partial(discount, amount=10)

Now, discount_10(15.00) is equivalent to discount(15.00, 10)

Task 3 is an trivial extension to Task2. Task 4 uses map in a straight-forward manner.

Ken Alger
STAFF
Ken Alger
Treehouse Teacher

Jose;

On which Task are you stuck, and what aspect?

Happy coding,
Ken

José Arturo González Navarro
José Arturo González Navarro
7,088 Points

Thank you for your answer Ken, I was stuck on task 2 but I got it now, Have a great day,

Jose