I'm working on the definitive igpay atinlay assignment. I've defined a module that has one function: def igpay(word): Its sole purpose is to process a word into pig latin. It seems to work well.
Now, the 2nd part of the assignment: Define a module that takes an argument on the command line (thanks to previous questions, this is complete) and processes the entire file into pig latin.
First I went through some basic tests to process the file: Find a space (for the delimiter), find punctuation and test for a capital. When I put this into a loop my logic doesn't seem to get it past the first word.
I think part of my problem is the temp assignment at the end. But I could use a gentle nudge to get this loop going because all it will do is process the first word right now.
Thank you
Now, the 2nd part of the assignment: Define a module that takes an argument on the command line (thanks to previous questions, this is complete) and processes the entire file into pig latin.
First I went through some basic tests to process the file: Find a space (for the delimiter), find punctuation and test for a capital. When I put this into a loop my logic doesn't seem to get it past the first word.
Code:
import sys import igpay filename = sys.argv[1] data = open( filename ) .read() print data def atinlay(data): for i in range(len(data)): #begin the loop space = data.find(" ") #find the first space period = data.find(".") #determine punctuation to handle later comma = data.find(",") temp = data[0:space] #get the first slice a = temp[:1] #copy the first letter to see if it is capital capital = a.isupper() if capital: temp = temp.lower() #make it lower case if it is capital newData = igpay.igpay(temp) #new temp variable if capital: #capital flag set? Handle it a = newData[:1] a = a.upper() newData = a + newData[1:] #put new cap back on word space += 1 #increment to new space? i = space #increment i? temp = newData[space:] #thought I needed another variable here.... :( return newData c = atinlay(data) print c
Thank you
Comment