vendredi 5 juin 2020

Incrementing the for loop in python given a certain condition

The i+=1 isn't working, it should have increased the I value but it isn't

n = int(input())

for j in range(n): a = input() pair = 0

for i in range(len(a)-1):
    print(i)
    if a[i] == "x" and a[i+1] == "y":
        pair += 1
        print("*")
    elif a[i] == "y" and a[i+1] =="x":
        pair += 1
        print('**')
    else:
        continue
    i+=1
    print(pair)
    print("****")
print(pair)strong text

Aucun commentaire:

Enregistrer un commentaire