python 学习之 Pig Latin

来源:互联网 发布:mysql 解锁 编辑:程序博客网 时间:2024/05/29 18:59
  • write a Pig Latin translator

    1. 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.

    2. 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_wordelse: 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 impprint a[1:4]

原创粉丝点击