•

Check out our Community Blogs

Register and join over 40,000 other developers!

### Recent Status Updates

• phi

I love this community !

• JackJames

hi i am jack i am seo expert jack james would love you to read new post

1 votes

# Getting TypeError

python error

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

### #1 coolasy

coolasy

CC Lurker

• Just Joined
• 1 posts

Posted 13 November 2015 - 02:24 PM

I keep getting this error, can somebody help me figure out what is wrong?

Traceback (most recent call last):
File "C:\Users\Andrew\Desktop\pa7.py", line 66, in <module>
main()
File "C:\Users\Andrew\Desktop\pa7.py", line 58, in main
valLength=CheckLength(cardNum)
File "C:\Users\Andrew\Desktop\pa7.py", line 15, in CheckLength
if len(num)>12 and len(num)<17:
TypeError: object of type 'builtin_function_or_method' has no len()

This is the code:

```def CheckLength(num):
if len(num)>12 and len(num)<17:
return True
else:
return False
def CheckType(num):
if num[0]=='4':
return 'Visa'
elif num[0]=='5':
return 'MasterCard'
elif num[0]=='6':
return 'Discover'
elif num[0:1]=='37':
return 'American Express'
else:
return 'Invalid Entry'
def Step1(num):
total=0
length=len(num)
for i in range(length-1,-2,-2):
double=int(num[i]*2)
if double>9:
double=double[0]+double[1]
total+=double
else:
total+=double
return total
def Step2(num):
total=0
length=len(num)
for i in range(length-1,-1,-2):
data=int(num[i])
total+=data
return total
def Step3(num):
total=Step1(num)+Step2(num)
if total%10==0:
return True
else:
return False
def main():
inFile=open('pa7.cards','r')
cardNum=inFile.readline().strip()
while cardNum!='99999':
valLength=CheckLength(cardNum)
valType=CheckType(cardNum)
if valLength==True and valType==True:
print(cardNum,"valid")
else:
print(cardNum,"invalid")
cardNum=inFile.readline().strip
inFile.close()
main()
```

This the data file:

```4388576018402626
4388576018410707
37271983
5190828258102121
99999

```

Also, do you see any other errors that could pop up in the code, i've been running into error after error on this assignment

### #2 dargueta

dargueta

I chown trolls.

• Moderator
• 4854 posts

Posted 20 November 2015 - 09:55 PM

You're missing the () on the function call here:

`cardNum=inFile.readline().strip()`

sudo rm -rf / && echo \$'Sanitize your inputs!'

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download