python学習のPig Latin

1684 ワード

  • write a Pig Latin translator
  • Pig Latin is a language game, where you move the first letter of the word to the end and add “ay.” So python become ythonpay. just like this.
  • the code
  • print 'Welcome to the Pig Latin translator!'
    name = raw_input("Enter a word:")
    if len(name) > 0 and name.isalpha():
     #method .isalpha()which returns False since the string contains non-letter characters
     word = name.lower()
     first = word[0]
     new_word = word + first 
     new_word = new_word[1:len(new_word)]
     print name
     print first
     print new_word
    else:
     print "the name is empty"
    3.the character
    
    #create a variable a and give it the stirng "Simple"
    
    a = "Simple"
    
    #get the first letter of it using a[0]
    
    print a[0]
    
    # get the other letter,will print imp
    
    print a[1:4]