Python core programming version 2 Chapter 8 exercise Part 2-Python core programming answers-self-developed-

Source: Internet
Author: User

The answer in this blog is not from official resources, but from my own exercises, which may be incorrect.

8-9. Fibonacci series. The Fibonacci sequence is like 1, 1, 2, 3, 5, 8, 13, and 21. That is to say, the next value is the sum of the first two values in the sequence. Write a function. Given N, return the nth Fibonacci number. For example, the 1st Fibonacci numbers are 1 and the 6th are 8.
[Answer]
The Code is as follows:

Def maid (number): fs = [0, 1] I = 1 for I in range (number-1 ): a = fs [-1] + fs [-2] fs. append (a) I + = 1 print fs [1:] return fs [-1] number = raw_input ("Please input a number... ") print maid (int (number ))

[Execution result]

Please input a number... 10 [1, 1, 2, 3, 5, 8, 13, 21, 34, 55] 55

8-10. Text Processing. Count the number of metachines, 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.
[Answer] I feel a little difficult at present. This question can only be left behind.

Keywords: Pyhon core programming answers unofficial

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.