The Fibonacci sequence of the PY practice

Source: Internet
Author: User

#-*-coding:cp936-*-

# Fibonacci Series

def fibs (num):

rest=[0,1]

For I in Range (num-2):

Rest.append (Rest[-2]+rest[-1])

return rest

Print fibs (10)

# Recursive

def f (n):

If n==1:

Return 1

Else

Return N*f (n-1)

Print F (6)

# Secret

Def p (x,n):

If n==0:

Return 1

Else

Return X*p (x,n-1)

Print P (2,1)

"""

Isalnum ()

2011-09-26 10:20:41| Category: Accompanying notes  | Tags:isalnum isalpha isdigit | Font Size Subscription

The description of the function is this:

Checks for an ASCII alphanumeric character; It is equivalent to "isalpha (c) or isdigit (c)".

It means checking for an Ascii alphanumeric character, equivalent to isalpha, or isdigit

Like what:

>>> seq=["foo", "x41", "? ~", "* * *"]

>>> [x for x in SEQ if X.isalnum ()]

[' foo ', ' x41 ']

S.isalnum () all characters are numbers or letters

>>>

"""

"""
girls=[' Alice ', ' Bernice ', ' Clarice '
boys=[' Chris ', ' Arnold ', ' Bob ']
lettergirls={}
For girl in Girls:
Lettergirls.setdefault (girl[0],[]). Append (Girl)
print [(b + ' + ' +g) for B in boys-G in lettergirls[b[0]]]
"""
f=[0,1]
Num=input (' num: ')
For I in Range (num-2):
F.append (F[-2]+f[-1])
Print F
f=[0,1]
Nun=input (' N: ')
For I in Range (nun-2):
Print I,
Print F[nun]

The Fibonacci sequence of the PY practice

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.