Newbie - 1st Program

Mark Smith linux at ptd.net
Sun Nov 9 21:03:02 EST 2003


Hi,

I'm trying to learn to program and Python seems to be the best "Starter"
language (I've sat through various C tutorials, but have never used the
language "in anger").
Actually, I think I have all the attributes of a hacker (not cracker) except
for programming ability...I hope to learn...

In trying to think of something to experiment with as my first
thought-of-myself program, I thought back to an algorythm that I once worked
out, which basically returns the number of possible routes in a cross
connect (or switch) given the number of ingress or egress ports.

It seems to work - great - but how would you make this more 'elegant' - I'm
sure it's horrible to an experienced hacker...

# Cross-Connect Calculator

# (c)2003 Mark A Smith
# Calculates the number of possible routes for a cross connect
# given a certain number of ingress & egress ports.

# Get number of ports from user

inputPorts = input("Enter number of Input Ports: ")
outputPorts = input("Enter number of Output Ports: ")


# Main Routine

totalPorts = float(inputPorts) + float(outputPorts)

#Debug statements
#print "Total Ports =", int(totalPorts)
#print "Divisor =", float(totalPorts/2)
#print "Subtraction =", int(totalPorts-1)

crossConnects = (totalPorts / 2) * (totalPorts - 1)

# Output

print "You have", int(crossConnects), "possible connection routes."

Any suggestions?

Thanks

Juglugs

-- This sentence is in Spanish when you are not looking.






More information about the Python-list mailing list