#!/usr/bin/python # -*- coding: utf-8 -*- def convert_to_pig_latin(input_string): pyg = 'ay' # this is the variable for the suffix in pig latin original = input_string ''' this is how to ask a user for input. Anytime I want to input raw data for the console to read, I would use this format. Set it equal to a variable then use the raw_input piece with parentheses and your question or requested input ''' if len(original) > 0: # len() returns the count of the characters # the "if" statement needs to have a condition word = original.lower() # This is to return a lowercase version of the input first = word[0] # This returns the first letter in the string new_word = word + first + pyg # concatenating the words # print original; turned this into a comment new_word = new_word[1:len(new_word)] # this takes all letters from second letters # adds new_word to total result return new_word else: return 'empty' def main(): original = raw_input('Enter a word:') new_word = convert_to_pig_latin(original) print 'Original text: %s' %(original) print 'Converted text: %s' %(new_word) if __name__ == "__main__": main()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question