Calculate the length of the string
Write a function that receives a string and returns the length of the string
Tip: In this exercise you should not use ready -made functions like Len in Python
Write a function that receives a string and returns the length of the string
Tip: In this exercise you should not use ready -made functions like Len in Python
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
let msg = 'error' alert(msg)This answer is only visible to premium members
This answer is only visible to premium members
def get_len(s): count = 0 # The number of letters for char in s: # For each character count += 1 # We increase the number of characters return count # Returns the number # An example of function string = input('enter your fullname: ') length = get_len(string) print(length)
def len1(word): count = 0 for i in word: count += 1 return(count) word = input('Enter a word : ') print(len1(word))
sentence = input("Enter a sentence: ") len_sentence = 0 # The number of letters for i in sentence: len_sentence += 1 # Added to each letter print(f'sentence length: {len_sentence}')
def length(text): counter = 0 for item in text: counter += 1 return counter
string=input("enter the string data>>>")
count=0
for i in string:
count+=1
print(count)
text = input("enter text : ")
count = 0
for i in text:
count += 1
print("string length = " , count)
tedad = 0 space = 0 string = input("please enter a string:" ) for i in string: if i == " ": space += 1 else: tedad += 1 print(tedad)
Submitting answers is currently unavailable.
You must be logged in to access this section.
Login/Sign up If you don’t understand the exercise or can’t solve it for any reason, that’s completely
normal—don’t worry 😊
Try checking out easier exercises and reviewing different answers
submitted by others. Gradually, you can move on to more challenging exercises. Also, your answer
might be correct even if it’s different from others.