Python Forum
Homework Teacher isnt helping need some help
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework Teacher isnt helping need some help
#1

This is wrong somewhere on the last 2 lines please help

# TODO: author

oneTwoThree = "123"
print(len(oneTwoThree))

montyPython = "Monty Python"
print(len(montyPython))

word = input("Please enter a word:123 ")
print("The length of " + word + " is " + len(3))
Reply
#2
The 'len' function takes a string as an input and returns the length of the string. In the last line, you used the number 3 as an input to len(), which doesn't work because 3 is not a string. 

If you want to find the length of the word entered by the user, write len(word)- word is the name of your variable
Reply
#3
Quote:print("The length of " + word + " is " + len(3))
You should also know that no one in python concatenates strings together like that, as in other languages.
The pythonic way is to use format/ the first being f string python3.6+ and format() for anything older.
>>> word = 'monty python'
>>> f"The length of {word} is {len(word)}"
'The length of monty python is 12'
>>> "The length of {} is {}".format(word, len(word))
'The length of monty python is 12'
Recommended Tutorials:
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Getting my choices to display fro some reason it isnt working. dgizzly 5 1,337 Oct-24-2022, 04:53 PM
Last Post: DeaD_EyE
  Code isnt working abdullahali 5 3,389 Oct-01-2018, 02:31 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

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