5 Replies - 5544 Views - Last Post: 27 April 2013 - 01:14 PM Rate Topic: -----

#1 Deaven  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 27-April 13

Pyg Latin Translator Code at codeacademy

Posted 27 April 2013 - 10:14 AM

Hey guys and gals I have been trying to learn some Python over at codeacademy and been stuck on this Pyg Latin Translator for a couple of days.

pyg = 'ay'
original = raw_input('Enter a word:')


def original_function():
    
    if len(original) > 0 and original.isalpha():
        word=original.lower()
        vowel=('a', 'e', 'i', 'o', 'u')
        if word[0] in vowel:
            new_word = str(orginal)+str(pyg)
            print (new_word)
    
        else:
            print 'consonant'
    
    else:
        print 'empty'

original_function()



So the code was working up until the new_word variable was introduced. it also had the print statement set to "print vowel", and thats what it would do. But the next step is to concatenate the pyg ("ay") variable to the orignal raw_input. I might be blind but I can't figure this out.

sorry the indentatons didnt make it into the copy and paste.


pyg = 'ay'
original = raw_input('Enter a word:')


def original_function():
    
    if len(original) > 0 and original.isalpha():
        word=original.lower()
        vowel=('a', 'e', 'i', 'o', 'u')
        if word[0] in vowel:
            new_word = str(orginal)+str(pyg)
            print (new_word)
    
        else:
            print 'consonant'
    
    else:
        print 'empty'



This post has been edited by sepp2k: 27 April 2013 - 10:17 AM
Reason for edit:: Fixed code tags (first closing tag was missing a slash)


Is This A Good Question/Topic? 0
  • +

Replies To: Pyg Latin Translator Code at codeacademy

#2 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2118
  • View blog
  • Posts: 3,244
  • Joined: 21-June 11

Re: Pyg Latin Translator Code at codeacademy

Posted 27 April 2013 - 10:23 AM

What doesn't work about your code now? Do you get an error message or wrong output? If the former: what's the error message? If the latter: which output did you expect (and why?) and which output did you get?
Was This Post Helpful? 0
  • +
  • -

#3 Deaven  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 27-April 13

Re: Pyg Latin Translator Code at codeacademy

Posted 27 April 2013 - 11:39 AM

View Postsepp2k, on 27 April 2013 - 10:23 AM, said:

What doesn't work about your code now? Do you get an error message or wrong output? If the former: what's the error message? If the latter: which output did you expect (and why?) and which output did you get?


If I run it in IDLE is highlights the quotations at the end of "Enter a word:" in red and says invalid syntax. In the code academy tutorial it says "Oops, did you accidentally delete the word variable".

To this point I just need it to print something like.

raw_input = atlas (the user enter atlas)

output would be

atlasay

if the user enters a word that starts with a consonant instead, it should print "consonant"
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2118
  • View blog
  • Posts: 3,244
  • Joined: 21-June 11

Re: Pyg Latin Translator Code at codeacademy

Posted 27 April 2013 - 11:58 AM

Well, if I try to run your code and enter a string that starts with a vowel, I get the error message "NameError: global name 'orginal' is not defined" on line 11. I don't know why you wouldn't get that error, but that's the problem. If I fix that typo, the code runs fine.
Was This Post Helpful? 0
  • +
  • -

#5 Deaven  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 27-April 13

Re: Pyg Latin Translator Code at codeacademy

Posted 27 April 2013 - 12:40 PM

I fixed the typo and still all I get is the error message 'invalid syntax", it's Python 3.3 though maybe I should switch to 2.7.

either way codeacademy is kind of dumb if the error is "Oops, did you accidentally delete the word variable"
Was This Post Helpful? 0
  • +
  • -

#6 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2118
  • View blog
  • Posts: 3,244
  • Joined: 21-June 11

Re: Pyg Latin Translator Code at codeacademy

Posted 27 April 2013 - 01:14 PM

Yes, the code won't work in Python 3 (print needs parentheses and raw_input doesn't exist).
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1