CodeSolved

Solved Programming Questions & Exercises

Calculate the length of the string

Practice Easy 179/ Download 2394 Views

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

15 Answers

This answer is only visible to premium members
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

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
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

This answer is only visible to premium members

Subscription is currently unavailable.
This answer is only visible to premium members
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

This answer is only visible to premium members

Subscription is currently unavailable.
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)
Amirgr Download Python
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}')
Alireza Download Python
def length(text):
  counter = 0
  for item in text:
    counter += 1
  return counter
Behcoder Download Python
string=input("enter the string data>>>")
count=0
for i in string:
    count+=1
print(count)
Shina Download Python
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)
<< Previous page 1 2 Next page >>

Submit answer

Submitting answers is currently unavailable.

×
×
Close