2011-04-06, 11:46 PM
Old thing, but my Pig Latin thing needs to do sentences (got that) and punctuation (don't got that). I used methods I could read based off of the response's methods. Fixed the list one, as well. Classmate pointed out eval which I'd entirely forgotten about which helped a lot:
As for the sentence, I have:
What comes out with a punctuation mark:
The last word is omitted entirely. I can't figure out where I should have it add the last word, either.
Code:
count = 1
lst = []
resp = raw_input("Enter a number to continue or n to exit: ")
while resp[0].lower() != "n":
lst.append(eval(resp))
resp = raw_input("Enter a number to continue or n to exit: ")
print
for a in lst:
print a,
if count % 7 == 0:
print
count += 1
print
count = 1
lst.reverse()
for b in lst:
print b,
if count % 7 == 0:
print
count += 1
print
sm = sum(lst)
print "The sum of the list is ", sm
print
avg = float(sm) / (len(lst))
avg = round(avg, 3)
print "The average of the list is ", avg
print
print "The largest number in the list is ", max(lst)
print
print "The smallest number in the list is ", min(lst)As for the sentence, I have:
Code:
sent = raw_input("Enter the sentence you would like to have translated: ")
broken = sent.split( )
for aword in broken:
p1 = ""
x = 0
if aword[-1] in ["!", ".", "?", ",", ":", ";"]:
aword = aword[:len(aword) - 1]
punct = aword[-1]
elif aword[0].lower() == "a" or aword[0].lower() == "e" or aword[0].lower() == "i" or aword[0].lower() == "o" or aword[0].lower() == "u":
aword = aword + "-" + "ay"
print aword,
elif aword[0].lower() == "y":
if aword[1] != "a" and aword[1] != "e" and aword[1] != "i" and aword[1] != "o" and aword[1] != "u":
aword = aword + "-" + "ay"
print aword,
elif aword[1] == "a" or aword[1] == "e" or aword[1] == "i" or aword[1] == "o" or aword[1] == "u":
aword = aword[1:] + "-" + aword[0] + "ay"
print aword,
elif aword[0].lower() != "a" and aword[0].lower() != "e" and aword[0].lower() != "i" and aword[0].lower() != "o" and aword[0].lower() != "u":
for eachLetter in aword:
if not eachLetter in "aeiouAEIOU":
p1 = p1 + eachLetter
x = x + 1
else:
break
aword = aword[x:]
aword = aword + "-" + p1 + "ay"
print aword,What comes out with a punctuation mark:
Code:
This program translates a word entered by the user into Pig Latin.
Enter the sentence you would like to have translated: The rabbit ran from the wolf.
e-Thay abbit-ray an-ray om-fray e-thay
>>>The last word is omitted entirely. I can't figure out where I should have it add the last word, either.

