Python title: Fibonacci number calculation; title: queued sequential output; title: Creation of the legal parentheses combination; Title: User Login (three chance)

Source: Internet
Author: User

Fibonacci Series Calculation B description

The Fibonacci sequence is as follows:

F (0) = 0, f (1) = 1

F (n) = f (n-1) + f (n-2)

Write a function that computes the Fibonacci sequence, using a recursive method to output all Fibonacci sequence elements that do not exceed n

Call the function above to complete the following functions:

The user enters an integer n, outputs all Fibonacci sequence elements not exceeding n, the elements and averages of the output sequence, and outputs in order, separated by commas and spaces

This topic is automatic review, please strictly follow the requirements of the specification of input and output.

def Jebona (n):ifn==0:          return 0elif N==1:          return 1     Else:          returnJebona (n1) + Jebona (n2) n=eval (input ()) Len=0ret=0ls=[] forIinchRange0, n+1): Ret= ret +Jebona (i) Len+=1ls.append (str (Jebona (i))) Ls.append (str (ret)) Ls.append (str (ret//len))Print", ". Join (LS)

Queued Sequential Output description

A group of people queued, each of them is described by a pair of integers (h, k), where h represents the height of the person, and K indicates the total number of people in the queue that is not less than the person in front of the person.

Implement an algorithm to output this queue in the correct order.

Input:

[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]

Output:

[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]
 from operator  == Itemgetter (1= Itemgetter (0), reverse == []for   in queue:    output.insert (item[1], item) print (output)

The generation description of the legal parentheses combination

Given the number of parentheses N, the writer generates all well-formed combinations of parentheses.

def foo (output, open, close, pairs):ifOpen = = Pairs and close = =pairs:ls.append (Output)Else:          ifopen<Pairs:foo (Output+"(", open+1, close, pairs)ifclose<Open:foo (Output+")", Open, close+1, pairs) n=eval (input ()) LS=[]foo ("',0,0, N) print (LS)

User Login (three chance) description

Give the user three times the opportunity to enter the user name and password, the following requirements:

1) Enter the first line to enter the user name ' Kate ', the second line to enter a password of ' 666666 ', the output ' login success! ', exit the program;

2) When a total of 3 input user name or password incorrect output "3 times user name or password is wrong!" Exits the program. ”。

#name_passwd. Pyi=0ret=1 forIinchRange0,3): Name=input () passwd=input ()ifName = ="Kate"and passwd = ="666666": Ret=0;  Break;ifRET = =0: Print ("Login Successful! ")Else: Print ("3 times the username or password is wrong! Exits the program. ")

Python title: Fibonacci number calculation; title: queued sequential output; title: Creation of the legal parentheses combination; Title: User Login (three chance)

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.