Difference between revisions of "Python Functions"
Jump to navigation
Jump to search
Line 17: | Line 17: | ||
pig_word = word[1:] + first_letter + 'ay' # the 1: means from index 1 all the way to the end | pig_word = word[1:] + first_letter + 'ay' # the 1: means from index 1 all the way to the end | ||
return pig_word | return pig_word | ||
==[[#top|Back To Top]] - [[Python|Category]]== |
Revision as of 13:39, 13 March 2020
def addnum(a,b): result = a +b return result print addnum(4,5)
Problem: find out if the word "dog" is in a string
def dog(mystring): return 'dog' in mystring.lower(): dog('dog ran away') true
Pig Latin
def piglatin(word): first_letter = word[0] "check if vowel if first_letter in 'aeiou': pig_word = word + 'ay' else: pig_word = word[1:] + first_letter + 'ay' # the 1: means from index 1 all the way to the end return pig_word