Python Forum
Embedding return in a print statement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Embedding return in a print statement
#1
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(' ')))
Reply
#2
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.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#3
Perhaps you mean
print("In your sentence, the number of words is:", len(sentence.split(' ')))
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Embedding python script into html via pyscript pyscript_dude 7 1,454 Apr-16-2023, 11:17 PM
Last Post: pyscript_dude
  Need help with Return statement Columbo 13 2,181 Sep-17-2022, 04:03 PM
Last Post: Columbo
  C++ python embedding comarius 0 803 Aug-26-2022, 02:01 AM
Last Post: comarius
  return vs. print in nested function example Mark17 4 1,674 Jan-04-2022, 06:02 PM
Last Post: jefsummers
  How to invoke a function with return statement in list comprehension? maiya 4 2,753 Jul-17-2021, 04:30 PM
Last Post: maiya
Question Embedding a python file online Dreary35 0 1,478 Jun-10-2021, 05:05 PM
Last Post: Dreary35
  Why doesn't this print statement work? stylingpat 10 5,596 Mar-23-2021, 07:54 PM
Last Post: buran
  Runs perfect in Python but fails to print last statement when converted to .exe. Help sunil422 3 2,750 Aug-13-2020, 01:22 PM
Last Post: deanhystad
  Need help merging/embedding duckredbeard 10 3,336 Aug-13-2020, 04:48 AM
Last Post: duckredbeard
  syntax error on return statement l_butler 5 3,029 May-31-2020, 02:26 PM
Last Post: pyzyx3qwerty

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020