Python 3.1.2 (r312:79360M, Mar 24 2010, 01:33:18) [GCC 4.0.1 (Apple Inc. build 5493)] on darwin Type "copyright", "credits" or "license()" for more information. >>> ================================ RESTART ================================ >>> >>> question5() >>> ================================ RESTART ================================ >>> >>> question5() >>> ================================ RESTART ================================ >>> 'The big red barn'.split(' ') ['The', 'big', 'red', 'barn'] >>> ord(' ') 32 >>> import re >>> re.search('[Dog|dog]','There is a dog') <_sre.SRE_Match object at 0x15bea30> >>> re.search('[Dog|dog]','There is a hog') <_sre.SRE_Match object at 0x15be9f8> >>> re.searchre.search('Dog|dog','There is a dog') Traceback (most recent call last): File "", line 1, in re.searchre.search('Dog|dog','There is a dog') AttributeError: 'module' object has no attribute 'searchre' >>> re.search('Dog|dog','There is a dog') <_sre.SRE_Match object at 0x15f9218> >>> re.search('Dog|dog','There is a hog') >>> re.search('[Dd]og','There is a hog') >>> re.search('[Dd]og','There is a Dog') <_sre.SRE_Match object at 0x15be9f8> >>> re.search('[^Dd]og','There is a Dog') >>> re.search('[^Dd]og','There is a hog') <_sre.SRE_Match object at 0x15f9218> >>> re.search('Dog.Dog','There is a Dog Dog') <_sre.SRE_Match object at 0x15be9f8> >>> re.search('Dog.Dog','There is a Dog hog') >>> re.search('Dog.Dog','There is a DogDog') >>> re.search('(blah )*.*he said','blah blah blah\, he said') <_sre.SRE_Match object at 0x15ea720> >>> re.search('(blah )+.*he said','blah blah blah\, he said') <_sre.SRE_Match object at 0x15ea760> >>> re.search('(blah )+.*he said','chickens\, he said') >>> re.search('(blah )*.*he said','chickens\, he said') <_sre.SRE_Match object at 0x15ea720> >>> None >>> if 'cat' SyntaxError: invalid syntax >>> if 'cat': print('hello') hello >>> if None: print('hello') >>> re.search('Dog.Dog','There is a Dog hog') >>> if re.search('Dog.Dog','There is a Dog hog'): print('hello') >>> if re.search('Dog.Dog','There is a Dog dog'): print('hello') >>> if re.search('Dog.Dog','There is a Dog Dog'): print('hello') hello >>> if 0: print('hello') >>> if 57: print('hello') hello >>> output = 5 >>> if output == 2 or 3: print('hello') hello >>> if (output == 2) or (output == 3): print('hello') >>> ================================ RESTART ================================ >>> >>> if re.search('^abc','abcdef') SyntaxError: invalid syntax >>> re.search('^abc','abcdef') <_sre.SRE_Match object at 0x15beb48> >>> re.search('^abc','123abcdef') >>> re_plural('cat') 'cats' >>> re_plural('dish') 'dishes' >>> re_plural('silly') 'sillies' >>> re.search('[\^]','abc^efg') <_sre.SRE_Match object at 0x15beb48> >>> discouragement() Welcome to the discouragement Program. You will be prompted to enter a sentence about your hopes and dreams. This program will do its best to dash all hope and make you feel bad. Enter your next desire as a full sentence or enter return if you are done I want a lot of money Why bother? Enter your next desire as a full sentence or enter return if you are done I want some exclusive tropical fish Not possible! Enter your next desire as a full sentence or enter return if you are done I want to be a professional athlete Don't bother trying to be a professional athlete Enter your next desire as a full sentence or enter return if you are done I want to be a complete failure There is no chance you can be a complete failure Enter your next desire as a full sentence or enter return if you are done I don't want to be a senator You don't know how to be a senator Enter your next desire as a full sentence or enter return if you are done We hope you had a thoroughly discouraging experience. If you need further discouragement, please try again. >>> search1 = re.search('Dog.Dog','There is a Dog Dog') >>> search1 <_sre.SRE_Match object at 0x15bed08> >>> search1.start() 11 >>> search1.end() 18 >>> search1.group(0) 'Dog Dog' >>> >>> 'I would like to be a senator' 'I would like to be a senator' >>> search2 = re.search('I.*(want|like|have) to','I would like to be a senator') >>> search2 <_sre.SRE_Match object at 0x15ea2a0> >>> search2.end() 15 >>> 'I would like to be a senator'[15:] ' be a senator' >>> 'There is no chance you can' +'I would like to be a senator'[15:] 'There is no chance you can be a senator' >>> divide_up_syllables('catamaran') Character c has_vowel False Syllable c Output So Far: Character a has_vowel True Syllable ca Output So Far: Character t has_vowel False Syllable t Output So Far: ca Character a has_vowel True Syllable ta Output So Far: ca Character m has_vowel False Syllable m Output So Far: ca|ta Character a has_vowel True Syllable ma Output So Far: ca|ta Character r has_vowel False Syllable r Output So Far: ca|ta|ma Character a has_vowel True Syllable ra Output So Far: ca|ta|ma Character n has_vowel False Syllable n Output So Far: ca|ta|ma|ra 'ca|ta|ma|ran' >>> divide_up_syllables('picture') Character p has_vowel False Syllable p Output So Far: Character i has_vowel True Syllable pi Output So Far: Character c has_vowel False Syllable c Output So Far: pi Character t has_vowel False Syllable t Output So Far: pic Character u has_vowel True Syllable tu Output So Far: pic Character r has_vowel False Syllable r Output So Far: pic|tu Character e has_vowel True Syllable re Output So Far: pic|tu 'pic|ture' >>> divide_up_syllables('chicken') Character c has_vowel False Syllable c Output So Far: Character h has_vowel False Syllable ch Output So Far: Character i has_vowel True Syllable chi Output So Far: Character c has_vowel False Syllable c Output So Far: chi Character k has_vowel False Syllable k Output So Far: chic Character e has_vowel True Syllable ke Output So Far: chic Character n has_vowel False Syllable n Output So Far: chic|ke 'chic|ken' >>> divide_up_syllables('broken') Character b has_vowel False Syllable b Output So Far: Character r has_vowel False Syllable br Output So Far: Character o has_vowel True Syllable bro Output So Far: Character k has_vowel False Syllable k Output So Far: bro Character e has_vowel True Syllable ke Output So Far: bro Character n has_vowel False Syllable n Output So Far: bro|ke 'bro|ken' >>> re_divide_into_syllables('broken') found search Output So far: bro End 3 found search Output So far: bro|ke End 5 just appended Output So far: bro|ken End 5 'bro|ken' >>> re_divide_into_syllables('catamaran') found search Output So far: ca End 2 found search Output So far: ca|ta End 4 found search Output So far: ca|ta|ma End 6 found search Output So far: ca|ta|ma|ra End 8 just appended Output So far: ca|ta|ma|ran End 8 'ca|ta|ma|ran' >>> re_divide_into_syllables('picture') found search Output So far: pi End 2 found search Output So far: pi|cture End 7 'pi|cture' >>> position =re.search('([^aeiou][aeiou]+[lr]e)|\ ([aeiou]+[cts]h)|([aeiou]+[^aeiou])|([cts]h[aeiouy]+)|\ ([^aeiou][aeiouy]+)','catamaran') >>> position.start() 0 >>> position.end() 2 >>> 'catamaran'[0:2] 'ca' >>> position =re.search('([^aeiou][aeiou]+[lr]e)|\ ([aeiou]+[cts]h)|([aeiou]+[^aeiou])|([cts]h[aeiouy]+)|\ ([^aeiou][aeiouy]+)','picture') >>> position.start() 0 >>> position.end() 2 >>> position =re.search('([^aeiou][aeiou]+[lr]e)|\ ([aeiou]+[cts]h)|([aeiou]+[^aeiou])|([cts]h[aeiouy]+)|\ ([^aeiou][aeiouy]+)','picture'[2:] ) >>> position.start() 1 >>> position.end() 5 >>> re.searech('Mar[iy]a?', 'Mary') Traceback (most recent call last): File "", line 1, in re.searech('Mar[iy]a?', 'Mary') AttributeError: 'module' object has no attribute 'searech' >>> re.search('Mar[iy]a?', 'Mary') <_sre.SRE_Match object at 0x15fd3a0> >>> re.search('Mar[iy]a?', 'Marya') <_sre.SRE_Match object at 0x15fd3d8> >>> re.search('Mar[iy]a?', 'Maria') <_sre.SRE_Match object at 0x15fd3a0> >>> re.search('Mar[iy]a?', 'Mari') <_sre.SRE_Match object at 0x15fd3d8> >>> re.search('Mar[iy]a?', 'Mark') >>> re.search('Mar?[iy]a?', 'Maia') <_sre.SRE_Match object at 0x15fd3a0> >>> re.search('M(ar)?[iy]a?', 'Maia') >>> >>> re.search('M(ar)?[iy]a?', 'Maia') >>> >>> re.search('Mar?[iy]a?', 'Maia') <_sre.SRE_Match object at 0x15fd3d8> >>> re.search('M(ar)?[iy]a?', 'Mia') <_sre.SRE_Match object at 0x15ea7e0> >>> re.search('Ma?r?[iy]a?', 'Mia') <_sre.SRE_Match object at 0x15fd3d8> >>> re.search('Ma?r?[iy]a?', 'Maia') <_sre.SRE_Match object at 0x15fd3a0> >>> re.search.('(ho)+',”The laugh sounded like 'hohoho'” SyntaxError: invalid syntax >>> re.search.('(ho)+',"The laugh sounded like 'hohoho'") SyntaxError: invalid syntax >>> re.search('(ho)+',"The laugh sounded like 'hohoho'") <_sre.SRE_Match object at 0x15ea820> >>> re.search('(ho)+',"The laugh sounded like 'hahaha'") >>> re.search('(ho)*',"The laugh sounded like 'hahaha'") <_sre.SRE_Match object at 0x15ea860> >>> re.search('(ho)*',"The laugh sounded like 'hahaha'").start() 0 >>> re.search('(ho)+',"The laugh sounded like 'hohoho'").start() 24 >>> output = '' >>> for character in 'hello': output = output + 'character'+'*' >>> output 'character*character*character*character*character*' >>> output = '' >>> for character in 'hello': output = output + character+'*' >>> output 'h*e*l*l*o*' >>> output = [] >>> for character in 'hello': output.append(character) >>> output ['h', 'e', 'l', 'l', 'o'] >>> mixed_list = [1,range(5),'the book',57,'dog',[1,2,4]] >>> mixed_list [1, range(0, 5), 'the book', 57, 'dog', [1, 2, 4]] >>> mixed_list[2]='the chicken' >>> mixed_list [1, range(0, 5), 'the chicken', 57, 'dog', [1, 2, 4]] >>> mixed_tuple = (1,range(5),'the book',57,'dog',[1,2,4]) >>> mixed_tuple[2] = 'the chicken' Traceback (most recent call last): File "", line 1, in mixed_tuple[2] = 'the chicken' TypeError: 'tuple' object does not support item assignment >>> 'hello'[2]='a' Traceback (most recent call last): File "", line 1, in 'hello'[2]='a' TypeError: 'str' object does not support item assignment >>> mixed_list[2:4] ['the chicken', 57] >>> mixed_list[4:] ['dog', [1, 2, 4]] >>> mixed_list [1, range(0, 5), 'the chicken', 57, 'dog', [1, 2, 4]] >>> mixed_list[0] 1 >>> len(mixed_list) 6 >>> for item in mixed_list: print(item) 1 range(0, 5) the chicken 57 dog [1, 2, 4] >>> 57 in mixed_list True >>> 45 in mixed_list False >>> mixed_list [1, range(0, 5), 'the chicken', 57, 'dog', [1, 2, 4]] >>> def change_item_2_to_blah(inlist): inlist[2]='blah' >>> mixed_list [1, range(0, 5), 'the chicken', 57, 'dog', [1, 2, 4]] >>> change_item_2_to_blah(mixed_list) >>> mixed_list [1, range(0, 5), 'blah', 57, 'dog', [1, 2, 4]] >>> self_referential_list=[1,2,3] >>> self_referential_list[0]=self_referential_list >>> self_referential_list [[...], 2, 3] >>> duck_list = ['duck','duck','duck','goose'] >>> duck_list.count('duck') 3 >>> duck_list.count('index') 0 >>> duck_list.index('duck') 0 >>> duck_list.index('goose') 3 >>> duck_list.rindex('duck') Traceback (most recent call last): File "", line 1, in duck_list.rindex('duck') AttributeError: 'list' object has no attribute 'rindex' >>> duck_list.append('duck') >>> duck_list ['duck', 'duck', 'duck', 'goose', 'duck'] >>> duck_list.extend(['duck','duck','goose']) >>> duck_list ['duck', 'duck', 'duck', 'goose', 'duck', 'duck', 'duck', 'goose'] >>> duck_list.append(['duck','duck','goose']) >>> duck_list ['duck', 'duck', 'duck', 'goose', 'duck', 'duck', 'duck', 'goose', ['duck', 'duck', 'goose']] >>> duck_list.pop() ['duck', 'duck', 'goose'] >>> duck_list ['duck', 'duck', 'duck', 'goose', 'duck', 'duck', 'duck', 'goose'] >>> duck_list.remove('goose') >>> duck_list ['duck', 'duck', 'duck', 'duck', 'duck', 'duck', 'goose'] >>> duck_list.reverse() >>> duck_list ['goose', 'duck', 'duck', 'duck', 'duck', 'duck', 'duck'] >>> duck_list.reverse() >>> duck_list ['duck', 'duck', 'duck', 'duck', 'duck', 'duck', 'goose'] >>> Number_list = [15,1,68,2,1.4] >>> Number_list [15, 1, 68, 2, 1.4] >>> Number_list.sort() >>> Number_list [1, 1.4, 2, 15, 68] >>> string_list = ['abc','emu','cat','aardvark'] >>> string_list.append() Traceback (most recent call last): File "", line 1, in string_list.append() TypeError: append() takes exactly one argument (0 given) >>> string_list.sort() >>> string_list ['aardvark', 'abc', 'cat', 'emu'] >>> string_list = ['abc','emu','cat','aardvark','Cat'] >>> string_list.sort() >>> string_list ['Cat', 'aardvark', 'abc', 'cat', 'emu'] >>> mixed_list [1, range(0, 5), 'blah', 57, 'dog', [1, 2, 4]] >>> mixed_list.sort() Traceback (most recent call last): File "", line 1, in mixed_list.sort() TypeError: unorderable types: range() < int() >>>