![]() |
Embedding return in a print statement - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: Embedding return in a print statement (/thread-21614.html) |
Embedding return in a print statement - Tapster - Oct-07-2019 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(' '))) RE: Embedding return in a print statement - ichabod801 - Oct-07-2019 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. RE: Embedding return in a print statement - Gribouillis - Oct-07-2019 Perhaps you mean print("In your sentence, the number of words is:", len(sentence.split(' '))) RE: Embedding return in a print statement - Tapster - Oct-07-2019 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. |