r/learnpython•
dethkruzer

Module not returning correct value, or am I missing something?

So, I'm trying to create a fairly simple module here. The idea is that the module would take the input of a single word from the primary module, and then test if that word is five characters or longer, if the word is composed only of letters, and if the word is composed only of numbers. Now, if it were to work correctly, the code would return True if the word was five characters or longer, and was not composed of only letters, or only numbers, and would return False if the input does not fulfill all three of these conditions. The process would repeat until it received an input that returned True.

Now, I threw together two different bits of code, though I'm pretty sure the second one is... kinda stupid. Here's the first one

def testaa(sana):
 toisto = 0
 while toisto == 0:
  if len(sana) > 4:
   if sana.isalpha == False:
    if sana.isdigit == False:
     return True
     toisto = 1
    else:
     return False
   else:
    return False
  else:
   return False

And here's the second one, even if I'm pretty sure that's not how an "and" is meant to be used. also, not quite complete yet, but this was just me throwing code at the wall to see if it would stick.

def testaa(sana):
 if len(sana) > 4 and sana.isalpha == False and sana.isdigit == False:
  tulos = True
 else:
  tulos = False

Posted Dec 1, 2019, 1:19 PM UTC

14
Loading comments…