0

is it necessary to use the return? why should I use the return?

Hello sololearnesrs, this code is from the book Head First Learn to code. Eric Freeman the result of this code is the same with or without the return answer def get_attribute(query, default): question = query + ' [' + default + ']? ' answer = input(question) if (answer == ''): answer = default print('You chose', answer) return answer hair = get_attribute('What hair color', 'brown') hair_length = get_attribute('What hair length', 'short') eye = get_attribute('What eye color', 'blue') gender = get_attribute('What gender', 'female') glasses = get_attribute('Has glasses', 'no') beard = get_attribute('Has beard', 'no') thank you very much

29th Jul 2018, 10:23 PM
Caty Zurano
Caty Zurano - avatar
3 Answers
+ 2
This code always displays the correct values only because the output is inside the function. Try to output the values of variables after assigning them the results of functions. Example: https://code.sololearn.com/cDijg5jBgLvU/#py
29th Jul 2018, 10:40 PM
Mishin870
Mishin870 - avatar
+ 2
if i do not use the return the value is None What hair color [brown]? You chose red hair = None great!!!
29th Jul 2018, 11:24 PM
Caty Zurano
Caty Zurano - avatar
0
hello thank you
29th Jul 2018, 11:21 PM
Caty Zurano
Caty Zurano - avatar