Welcome to the Treehouse Community
The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.
How can I call a function that returns multiple inputs with a function that takes multiple inputs without TypeError?
This may be a little advanced for this lesson. I took the input calls and combined them into a method called "get_input()" that returns multiple values like this:
def get_input(): total_due = float(input("What is the total: ")) amount_of_people = int(input("What is the amount of people: ")) return total_due,amount_of_people
I then called this function with split_check() that accepts two inputs, total and amount_of_people like this:
amount_due = split_check(get_input())
When I did this, I received a TypeError. The only way I have found around this is to capture the results of get_input() using this:
input_total, input_amount_of_people = get_input()
By then calling split_check(input_total,input_amount_of_people), the script runs correctly. Is there a way to call split_check(get_input()) without a TypeError? Would I have to return a tuple or another type from get_input() and accept this new type in split_check()?
Kevin Gates14,830 Points
Can you update your question via the markdown cheatsheet? Specifically using the backticks and add the language you're using.
Steven Parker210,872 Points
Since "split_check" requires two arguments, there's nothing you can do to "get_input" to make its output usable directly for input. But you could modify "split_check" to take a tuple, or create an intermediate conversion function:
def split_check_from_tuple(tup): return split_check(tup, tup)
Then you should be able to: "
amount_due = split_check_from_tuple(get_input())".
Patrick Townley3,472 Points
Actually - you're already returning a tuple:
And since you're already returning a tuple, all you need to do is unpack that tuple using the
* operator when you send it to
amount_due = split_check(*get_input())