8-9 Fibonacci series. the Fibonacci sequence is like 1, 1, 2, 3, 5, 8, 13, 21, and so on. that is to say, the next value is the sum of the first two values in the sequence. write a function. Given N, the return value is the nth Fibonacci number.
# Filename: test8-9.pydef maid (N-1): If n <= 0: Return-1 Elif n <= 2: return 1 else: Return maid (N-2) + maid) # recursive print Fibonacci (6)
8-10. text processing. count the number of vowels, consonants, and words (separated by spaces) in a sentence. ignore special situations of vowels and consonants, such as "H", "Y", and "Qu. additional question: write the code to handle these special situations
# Filename: test8-10.pyimport stringletters = set (string. uppercase) vowels = set ('aeiou') def dealtext (): vlen = 0 clen = 0 text = raw_input ("Enter text :"). upper () WLEN = Len ([word for word in text. split ()]) tlen = sum ([Len (Word) for word in text. split ()]) CQU = text. count ('qu') # count the number of occurrences of special characters and filter out CH = text. count ('H') Cy = text. count ('y') # print CQU, CH, Cy, tlen vlen = Len ([X for X in text if X in vowels]) -In CQU # Qu, 'U' should be excluded from the vowel clen = tlen-vlen-2 * CQU-ch-cy # exclude 'q' u'h 'y' print WLEN, vlen, clen dealtext ()