Doris,2016.7.9+chapter8

=Chapter 8 2016,7,10=

exercise
1. (1)y (2) g (3) 9 (4) myst (5) True (6) True (7) False (8) False (9) False 2. code format="python" prefixes = "JKLMNOPQ" suffix = "ack" for letter in prefixes: if letter == 'O' or letter == 'Q': print(letter + 'uack') else: print(letter + suffix) code 3. code format="python" def count_fuction(a,char): count = 0 for i in a:       if i == char: count += 1 return count print(count_fuction('abccccc','c')) code 5. code format="python" import string sentence='' count=0 a='asd asde asd' for i in a:   if i not in string.punctuation: sentence=sentence+i words=sentence.split

for j in words: if 'e' in j:       count += 1 print('your sentence contain',len(words),'words','of which',count,'(',count/len(words),'%) contain an "e".')

code 6. code format="python" for i in range(1,13): print(i,i*2,i*3,i*4,i*5,i*6,i*7,i*8,i*9,i*10,i*11,i*12) code 7. code format="python" def reverse(n): new=n[::-1] return new print(reverse(abide)) code 8. code format="python" def mirror(n): new = n[::-1] new = n + new return new code 9. code format="python" def remove_letter(a,char): words='' for letter in a:       if letter != char: words=words+letter return words print(remove_letter('aabbcc','c')) code 10. code format="python" def is_palindrome(n): if n == n[::-1]: return True else: return False print(is_palindrome('abcba'))

code 11. code def count(a,char): count=0 n=0 while n < len(a): n=n+1 if char in a[n+1-len(char):n+1]: count=count+1 return(count) print(count('aaabbbccc','bc')) code 12. code format="python" def remove(a,char): words='' n=0 while n<len(a): n=n+1 if char in a[n+1-len(char):n+1]: words=a[:n+1-len(char)]+a[n+1:len(a)+1] break return words print(remove('aaabbbccc','ccc')) code 13. code format="python" def remove_all(a,char): while char in a:       for i in range(len(a)): if char in a[i+1-len(char):i+1]: a =a[:i+1-len(char)]+a[i+1:len(a)+1] return a print(remove_all('aaabbbcccccc','cc')) code