We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,534 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Python Help Please!

Whats up guys! To start off I am really new to python. I got this program that keeps giving me this error message. I was wondering if anyone could help me. Heres the code:

from math import *
from numberTest import *

Lname=['Zdofalos','Johnson','Terrell','Wilson','Key','Smith','Alfonso']
Fname=['Fred','Malcom','Monkey','Wilson', 'LeDoor','Jim Bob','Ralph']
City=['Charlotte','Monroe','Broken Pine','Hogwart','Spot In Road','Denver','Gastonia']
State=['NC','NC','SC','VA','AL','NC','NC']
Zip=['28210','28337','28974','27457','36827','28037','28559']

# =============================================== Menu Items
def main():
    sort01 = sort01()
    sort02 = sort02()
    print 'Which way do you want your list?';print
    item1='1 - Enter one for Ascending.'
    item2='2 - Enter two for Descending.'
    item4='3 - Enter three to exit the program.'
    item5='Enter your selection and Press Enter: '
    sp=0

# ============================================== Ascending Order

def sort01(sort01):
    sort01=len(Zip)
    for i in range(sort01-1,0,-1):
        for j in range(0,i,1):
            if Zip[j] > Zip[j + 1]:
                Zip[j],Zip[j + 1] = Zip[j + 1],Zip[j]
                State[j],State[j + 1] = State[j + 1],State[j]
                City[j],City[j + 1] = City[j + 1],City[j]
                Fname[j],Fname[j + 1] = Fname[j + 1],Fname[j]
                Lname[j],Lname[j + 1] = Lname[j + 1],Lname[j]


print           
print 'The list in ascending order.'
print
print ' Zip        State        City        First Name     Last Name'
print '--------------------------------------------------------------'
for i in range(sort01):
    print Zip[i],State[i],City[i],Fname[i],Lname[i]

print
print


# =========================================== Descending Order

def sort02(sort02):
    sort02=len(Lname)
    for i in range(sort02-1,0,-1):
        for j in range(0,i,1):
            if Lname[j] < Lname[j + 1]:
                Lname[j],Lname[j + 1] = Lname[j + 1],Lname[j]
                Fname[j],Fname[j + 1] = Fname[j + 1],Fname[j]
                City[j],City[j + 1] = City[j + 1],City[j]
                State[j],State[j + 1] = State[j + 1],State[j]
                Zip[j],Zip[j + 1] = Zip[j + 1],Zip[j]       


print            
print 'The list in descending order.'
print
print ' Last Name        First Name        City       State      Zip'
print '--------------------------------------------------------------'
for i in range(sort02):
    print Lname[i],Fname[i],City[i],State[i],Zip[i]

# =============================================== Menu Prompt    

def menu():

    john=0
    while john==0:

        print sp*'n'
        print sp*' ',item1
        print sp*' ',item2
        print sp*' ',item3
        print

        selection=raw_input()

        john,selection=testinteger(selection)

        if john==1:
            if selection<1 or selection>4:
                john=0
                print 'Your selection is out-of-range!'
                raw_input('Press Enter to retry!')
            elif selection==1:
                sort01()
                john=0
            elif selection==2:
                sort02()
                john=0
            elif selection==3:
                print 'Thanks You for using this program!'
                raw_input('Press Enter to exit.')
                john=1
            else:
                print 'There might be a problem with the program!'
    return


menu()

I can't seem to figure out how to display the items directly in the colums listed. And heres the error message:

TypeError: range() integer end argument expected, got function.

Thanks for any help.

ADMIN EDIT
Highlight your code next time (shift-up after posting) and push TAB to do easy code formatting.

2
Contributors
3
Replies
16 Hours
Discussion Span
1 Year Ago
Last Updated
4
Views
Kaptain Khronic
Newbie Poster
2 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

What this is supposed to mean?

def sort01(sort01):
     sort01=len(Zip)

You are defining function, with the function itself as parameter and then shadowing it with length of Zip list.

See

def sort01(sort01):
    print sort01
    print sort01(Zip)
    sort01=len(Zip)
    print sort01

sort01(len)
pyTony
pyMod
Moderator
6,331 posts since Apr 2010
Reputation Points: 879
Solved Threads: 990
Skill Endorsements: 27

Well that was the part where I was trying to create modules for this program and as you can see I am not good with modules at all.

The sort01 and sort02 are the two sorting patterns for the program. (ascending and descending)

Kaptain Khronic
Newbie Poster
2 posts since Apr 2012
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

You must work throug some basic tutorial, before you are ready to start python.org's tutorial is fine, you can find it from IDLE's Help system or net here

pyTony
pyMod
Moderator
6,331 posts since Apr 2010
Reputation Points: 879
Solved Threads: 990
Skill Endorsements: 27

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0915 seconds using 2.74MB