Let's revisit our lucky_number function. We want to change it, so that instead of printing the message, it returns the message. This way, the calling line can print the message, or do something else with it if needed. Fill in the blanks to complete the code to make it work.

def lucky_number(name):
number = len(name) * 9
___ = "Hello " + name + ". Your lucky number is " + str(number)
___

print(lucky_number("Kay"))
print(lucky_number("Cameron"))

Respuesta :

Answer:

Replace the first blank with:

message = "Hello " + name + ". Your lucky number is " + str(number)

Replace the second blank with:

return message

Explanation:

The first blank needs to be filled with a variable; we can make use of any variable name as long as it follows the variable naming convention.

Having said that, I decided to make use of variable name "message", without the quotes

The next blank is meant to return the variable on the previous line;

Since the variable that was used is message, the next blank will be "return message", without the quotes

fichoh

In other to make the function lucky_number return the message rather than print, we use the return keyword.

def lucky_number(name):

number = len(name) * 9

message = "Hello " + name + ". Your lucky number is " + str(number)

return message

In other to return a variable or expression in a defined function such as the lucky_number function defined above, all we have to do is use the return keyword with the message.

When we use :

  • print(message) : the output when the lucky_number function is called is that, content of the message variable is printed or displayed.
  • However, return message would return message back to the caller making it useful in other parts of our program.

The returned value could also be printed using the statement :

print(lucky_number(name)) : This statement prints the content of the returned message variable.

Learn more : https://brainly.com/question/17027551

ACCESS MORE
ACCESS MORE
ACCESS MORE
ACCESS MORE