I'm trying to compare two strings, comparing every character so that the number of characters in common in the same positions, the more points the terminal will return.
Here's the code:
resultado=input('Resultado correcto: ')
apuesta=input('Apuestas: ')
puntos=0
contador=0
while contador <= len(resultado):
if resultado[contador] == apuesta[contador]:
puntos = puntos +1
else:
puntos = puntos
contador+=1
print(puntos)
But when I run the program, it gives me the next error:
if resultado[contador] == apuesta[contador]:
IndexError: string index out of range
I don't know what's wrong, but I guess it has something to do with the counter and the number of characters. It's worth noting that both inputs have the same number of character e.g. Hello and Hello.
Aucun commentaire:
Enregistrer un commentaire