
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Concept explainers
Question
Answer the given question with a proper explanation and step-by-step solution.
using while loop

Transcribed Image Text:Fibonacci series
The Fibonacci series proceeds as follows:
0 1 1 2 3 5 8 13 21
Each new term is the sum of the preceding two terms; see here.
Task 1
Task
Write a Python script named fib-n.py which reads a positive integer n from standard input and
outputs the first n numbers in the Fibonacci series, one per line.
Example standard input
6
Example standard output
...
1235TO
Tip
This is possibly harder than the previous examples. You will have to keep track of two values, the
previous value and the current value.
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 3 images

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- please read the question carefully and answer the question carefullyarrow_forward- Question Completion Status: Quèstion 7 (Big-O Analysis) Total number of comparisons in algorithm A is 2n² +n+1 and total number of comparisons in algorithm B is 2nlog(n) + 8n, where 'n' is input size. (The base of log is 2). Order of algorithm A is O( (a) ). Order of algorithm B is O( (b)). What is (a) and (b) ? O (a): n², (b): n2 o (a): n2, (b): nlog(n) (a): n, (b): nlog(n) (a): n2 +n, (b): log(n) ows b A Moving to another question will save this response.arrow_forwardUse pseudocode to describe an algorithm that takes as input a list of n distinct integers and finds the location of the smallest odd integer in the list or returns 0 if there are no odd integers in the list. (Note: Use the operation "is odd" in your code, or similar; don't attempt to craft odd-ness checking logic.)arrow_forward
- Example-The Factorial Function To illustrate the operation of a for loop, we will use a for loop to calculate the factorial function. The factorial function is defined as n = 0 – 1) × (n – 2) × ... X 2x1 n>0 n! = (5.3) The MATLAB code to calculate N factorial for positive value of N would be n_factorial = 1 for ii = 1:n n_factorial = n_factorial * ii; end Suppose that we wish to calculate the value of 5!. If n is 5, the for loop control expression would be the row vector [1 2 3 4 5]. This loop will be executed 5 times, with the variable ii taking on values of 1, 2, 3, 4, and 5 in the successive loops. The resulting value of n_factorial will be 1 X 2 x 3 x 4 x 5 = 120. MATLAB includes a standard function called zactoriai to calculate the factorial function. Use the MATLAB help system to look up this function. Calculate 71, 141, and 21! using the program ini this example 7! = 14! = 21! = Calculate 7!, 14!, and 21! using the factorial function. 7! = 14! = 21! = How do the results compare?arrow_forwardThere are three subtleties in the design of enumeration-controlled loops that are presented.arrow_forwarddefine iteration.arrow_forward
- - .is Complete history of everything that the agent has ever perceived. * Percept percept sequence Agent functions Nonearrow_forwardi = 1 while (i < n) do s = s + i i = i * 2 enddo Is the step count dependent on which term?arrow_forwardIN VISUAL BASIC, solve Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be: 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, ... By considering the terms in the Fibonacci sequence whose values do not exceed four million, find the sum of the even-valued terms.arrow_forward
- solve code in matlabarrow_forwardWrite a recursive algorithm with the following prototype: int add (int x, int y); that returns x if y is 0; and adds x to y otherwise. THE FUNCTION MUST BE RECURSIVE. (hint: the base case should involve a test for y being 0; recursive case should reduce y towards 0)arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education