Boyah Forums

General => Internet, Science, & Technology => Topic started by: Daddy on March 06, 2009, 05:05:53 PM

Title: PYTHON HELP
Post by: Daddy on March 06, 2009, 05:05:53 PM
Code Select
def isPandigital(n):
digList = list(str(n))
for i in digList:
if str(i) in digList:
continue
else:
return False
return max(digList) == len(str(n))
print isPandigital(3142)


Keeps returning False. HOWEVER
Code Select
def isPandigital(n):
digList = list(str(n))
for i in digList:
if str(i) in digList:
continue
else:
return False
return max(digList)
print isPandigital(3142)

Will return 4

and
Code Select
def isPandigital(n):
digList = list(str(n))
for i in digList:
if str(i) in digList:
continue
else:
return False
return len(str(n))
print isPandigital(3142)

Also returns 4, which both are correct.

So I don't get why it returns false, because if you have the == isn't it the same as saying:

return 4 == 4, which would be true?
ffffffffffff
Title: Re: PYTHON HELP
Post by: Feynman on March 06, 2009, 06:18:37 PM
Did you set it to Wumbo?
Title: Re: PYTHON HELP
Post by: mario583 on March 07, 2009, 06:15:21 AM
Quote from: Bassir on March 06, 2009, 06:18:37 PM
Did you set it to Wumbo?

I Wumbo, you wumbo, he, she, me, wumbo, wumbo, wumboing, I'll have three wumbo, wumbora, wumbology, the study of wumbo? It's first grade, JMV! bassir;
Title: Re: PYTHON HELP
Post by: guff on March 07, 2009, 08:31:54 AM
Quote from: Raekewn on March 06, 2009, 05:05:53 PM
Code Select
def isPandigital(n):
digList = list(str(n))
for i in digList:
if str(i) in digList:
continue
else:
return False
return max(digList) == len(str(n))
print isPandigital(3142)
what the lol how is that testing if it's pandigital
all that for loop is doing is checking to see if each element of digList is an element of digList, which is obviously true
also, there's not really a reason to make digList a list because strings are iterable too
and the reason that it returns false is that you're comparing a string ("4") to an int (4) which will always evaluate to false

but basically if you actually want to test for pandigitalness then you've got to generate a list of the numbers from 1 to n (range(1, n + 1)), then check to see if each digit of your input is in that list and that the lengths are the same baddood;