Difference between revisions of "Python Functions"
Jump to navigation
Jump to search
(Created page with " 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.low...") |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 8: | Line 8: | ||
dog('dog ran away') | dog('dog ran away') | ||
true | 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 | |||
==[[#top|Back To Top]] - [[Python|Category]]== | |||
[[Category:Python]] |
Latest revision as of 16:20, 1 September 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