str=input("input")
count=0
for i in str:
???
A or B is entered (for example, AAABBABABAB
or BBBAAABABABA
).
I want to calculate it like the count value 12323454321
If the same character appears consecutively, increase the count value by 1 and decrease the count value by 1 if the character is wrong
I want to make a for door, but it's hard because I'm a Ask how to construct a for statement...
string = input ('input')
pre = string[0]
count = 0
for s in string:
if s == pre:
count += 1
else:
count += -1
pre = s
print(count, end='')
© 2025 OneMinuteCode. All rights reserved.