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
let msg = 'error' | |
alert(msg) |
This answer is only visible to premium members
let msg = 'error' | |
alert(msg) |
This answer is only visible to premium members
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 |
tedad = 0 | |
space = 0 | |
string = input("please enter a string:" ) | |
for i in string: | |
if i == " ": | |
space += 1 | |
else: | |
tedad += 1 | |
print(tedad) |
fun main() { | |
try { | |
println("Please Enter a series of words or numbers or signs as desired ") | |
val string1 = readln() | |
val length3 = stringToInt(string1) | |
println(length3) | |
} catch (e: Exception) { | |
println(e.message) | |
} | |
} | |
fun stringToInt(string1: String): Int { | |
val list1 = mutableListOf<Char>() | |
var number = 0 | |
for (char in string1) { | |
list1.add(char) | |
number += 1 | |
} | |
return number | |
} |
def my_len(string): | |
""" | |
Calculate the length of a string manually | |
Arguments: | |
string: The string whose length we want to calculate | |
Return value: | |
string length | |
""" | |
count = 0 | |
for char in string: | |
count += 1 | |
return count | |
# Example of using the function | |
my_string = "hello world" | |
length = my_len(my_string) | |
print("string length:", length) |
String n; | |
int lowerCase = 0, upperCase = 0; | |
char currentChar; | |
Scanner input = new Scanner(System.in); | |
System.out.println("Enter a String : "); | |
n = input.nextLine(); | |
for (int i = 0; i < n.length(); i++) { | |
currentChar = n.charAt(i); | |
if (Character.isLowerCase(currentChar)) { | |
lowerCase++; | |
} else if(Character.isUpperCase(currentChar)) { | |
upperCase++; | |
} | |
} | |
System.out.println("Lower Case is : " + lowerCase); | |
System.out.println("Upper Case is : " + upperCase); |
def lennn(): | |
string = input('Enter a string : ') | |
lenn = 0 | |
for i in string: | |
lenn+=1 | |
print(lenn) | |
lennn() |
Submitting answers is currently unavailable.
1- The system randomly selects a number between 1 and 100 2- The user tries to guess the selected number 3- After each user guess, if the number entered is correct, the program will end. Otherwise the schedule ...
Style the FIX class using CSS to constantly place in the lower left corner of the screen (10 pixels) and the position does not change if the user scrolls.
Write a program that receives a number and prints the following figure according to the number received: Number: 55555 4444 333 2 2 1
Write a program that receives a one -digit number from the input and finds the coefficient of smaller than 100 of those numbers and prints in the output
برای استفاده از این بخش باید وارد حساب کاربریت بشی
ورود/ثبت نام 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.