str1 = "I like nonsense, it wakes up the brain cells. Fantasy is a necessary ingredient in living."
Answers
Answer:
str1 = "I like nonsense, it wakes up the brain cells. Fantasy is a necessary ingredient in living."
numbs = 0
i for i in str1:
numbs = numbs + 1
print(numbs)
Explanation:
step 1: initialize a variable numbs with value 0
step 2: then loop through the string and add 1 for each iteration.
this will give same result as the following code:
numbs = len ( str1 )
The following codes have been written using Python.
Source code:
str1 = "I like nonsense, it wakes up the brain cells. Fantasy is a necessary ingredient in living."
numbs = 0
for i in str1:
numbs += 1
print(numbs)
Output:
90
[Note that characters include spaces and punctuation marks as well.]
A for-loop is a control statement used for iteration/repeated checking.
In a for loop, the variable keeps iterating for the given range.
Here, the given range was str1. The variable given was 'i '.
The value of 'i' keeps changing each time it is incremented.