Python Forum

Full Version: Embedding return in a print statement
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
First, I hope I used the format/rules correctly.
I did a search for "embedding return in a print statement" before posting. I don't have the terminology down and may not be asking a syntactically correct question. If that's not a proper way to word the question I'm asking, please identify the correct way to word it if you would.
The last line of the code gives me the correct return. I want that same return embedded in the previous print statement but don't know the correct structure and would be appreciative of knowing/seeing it.
Thanks in advance.

print("Word Counter")
print("The purpose of the word counter is to enter the count of the number of words in a sentence entered into the system by the user.")
sentence = input("Enter the sentence you would like to test. When done, press Enter."'\n')
print("The sentence you entered is:") 
print(sentence)
print("In your sentence, the number of words is: (len(sentence.split(' ')))")
print(len(sentence.split(' ')))
You don't have a function there. All return statements must be in a function (or method). Also, return is a statement, print is a function. You can't have a statement in a function call, only expressions.
Perhaps you mean
print("In your sentence, the number of words is:", len(sentence.split(' ')))
That was the structure I was looking for Grib. Thanks.

ichabod:
If I had used the term output in place of return would you have given me a different answer. If not, I'm not sure what your trying to tell me.

Thanks to both of you for taking the time and adjusting my thought process.