Recursive perrin numbers..     # DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE cod will be here # DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE with open("output.txt") as r: print(r.read(), end="")

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question

Recursive perrin numbers..

 

 



# DO_NOT_EDIT_ANYTHING_ABOVE_THIS_LINE

cod will be here

# DO_NOT_EDIT_ANYTHING_BELOW_THIS_LINE
with open("output.txt") as r:
print(r.read(), end="")

Description
Your task is to calculate and write to a file the nth Perrin number starting from the first, second and third Perrin number recursively. The number n will be provided by the user.
The name of the file you will print the nth Perrin number is output.txt and do not add any other characters besides printing the number.
Assume that the number n will always be a positive integer. The Perrin formula is provided in the image below.
You must handle the input taking part too, and DO NOT WRITE ANY PROMPTS for the user while taking the input.
Definition: Perrin sequence is a sequence where the next number in the sequence is the sum of the two previous numbers within the sequence.
Explanation: First three Perrin numbers are known: first is 3, second is 0 and third is 2. Calculation of the fourth Perrin number is as follows:
4th Perrin Number = (4-2)nd Perrin Number + (4-3)st Perrin Number = 0 + 3 = 3
5th Perrin Number = (5-2)rd Perrin Number + (5-3)nd Perrin Number = 2 + 0 = 2
6th Perrin Number = (6-2)th Perrin Number + (6-3)rd Perrin Number = 3 + 2 = 5
%3D
%3D
Pn = Pn-2+ Pn-3 where P = 3, P2 = 0, P3 = 2
%3D
Check the examples for further clarification. Keep in mind that we will be grading your code not just based on these examples, but other cases as well,
so try to write code which can handle all possible cases.
Warning 1: You are not allowed to use imports and topics that haven't been covered this semester.
Warning 2: Non-recursive implementations will be detected by manual inspection and get no points. For the purposes of this question, solving it iteratively and then calling another function recursively does not count as
a recursive implementation.
Hint: Think about what can be your base cases and recursive case from the given formula.
Examples:
INPUT
OUTPUT
5
17
90
1
Transcribed Image Text:Description Your task is to calculate and write to a file the nth Perrin number starting from the first, second and third Perrin number recursively. The number n will be provided by the user. The name of the file you will print the nth Perrin number is output.txt and do not add any other characters besides printing the number. Assume that the number n will always be a positive integer. The Perrin formula is provided in the image below. You must handle the input taking part too, and DO NOT WRITE ANY PROMPTS for the user while taking the input. Definition: Perrin sequence is a sequence where the next number in the sequence is the sum of the two previous numbers within the sequence. Explanation: First three Perrin numbers are known: first is 3, second is 0 and third is 2. Calculation of the fourth Perrin number is as follows: 4th Perrin Number = (4-2)nd Perrin Number + (4-3)st Perrin Number = 0 + 3 = 3 5th Perrin Number = (5-2)rd Perrin Number + (5-3)nd Perrin Number = 2 + 0 = 2 6th Perrin Number = (6-2)th Perrin Number + (6-3)rd Perrin Number = 3 + 2 = 5 %3D %3D Pn = Pn-2+ Pn-3 where P = 3, P2 = 0, P3 = 2 %3D Check the examples for further clarification. Keep in mind that we will be grading your code not just based on these examples, but other cases as well, so try to write code which can handle all possible cases. Warning 1: You are not allowed to use imports and topics that haven't been covered this semester. Warning 2: Non-recursive implementations will be detected by manual inspection and get no points. For the purposes of this question, solving it iteratively and then calling another function recursively does not count as a recursive implementation. Hint: Think about what can be your base cases and recursive case from the given formula. Examples: INPUT OUTPUT 5 17 90 1
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY