The user must set the sequence himself.
A character string is given; count how many times among the characters in the string
the letter “x” is encountered.
In principle, the task is not difficult, I just can’t figure out what doesn’t work here:
Divide the sequence into individual elements, then set the condition that when this element is encountered, I use count to count the number of elements.
n = list () n = input ("Enter the sequence:") n.split () i = 0 for i in n: i + = 1 if (i == 'x'): s.count ('x') print (n)
You first write
n = list () and then the same n becomes
input () , you assign different values to one variable. If you want to wrap the entered string in a list, you can do
list (input (). Split ())
Or like this, if you enter a sequence separated by a space:
n = [i for i in input ("Please enter a sequence:") .split ()] x = n.count ('x') print (x)
Or easier, if you enter any line:
n = input ("Enter the sequence:") x = n.count ('x') print (x)