I have a little problem with some coding. This is my code:
def sites(x):
r = []
sum = 0
i = 0
modulo = []
som = 0
j = 0
while i < len(x):
sum = int(float(x[i])) + (i + 1)
r.append(sum)
i = i + 1
while j < len(x):
som = r[j] % len(x)
modulo.append(som)
j = j + 1
return modulo
If I for example fill in sites("321") this code will give me the list [1, 1, 1]. What I want to do is check if there are numbers in this list that are the same. I was thinking about something like:
if modulo[0] != modulo[1] != modulo[2]:
print "valid"
else:
print "invalid"
This only works when the input in sites is three digits long. I've been brainstorming on how to use a while loop that checks every digit.
All help is very welcome.
Aucun commentaire:
Enregistrer un commentaire