-1

How can I print both result of a function and characters?

x = input("Write your number: ")    
def fct1(n):
    if n == 10:
        print 'ten'         
def apple(n):
    return fct1(n) + 'apples'       
apple(x)

In my printing message I want to see 'ten apples'. What is the problem? This is not about only "ten" case. I explained shortly. Let's say I have in fct1(n) ten values. The point is I want to see 'three apples' or 'six apples' depending on the number I write

1 Answers1

0

You can't print the function if it does not return anything.

So you can either (on apple-function):

fct1(n)
print ' apples'

Or on fct1(n) you don't print the 'ten' string but instead return it:

return 'ten'

and then you can do print fact(n) + apples on the apple-function.

Using return is better if you need to do something else with the result after printing it.

anrah
  • 1