Question: I need help converting this program from c++ to python. I have started working on it in python but I am not able to understand

I need help converting this program from c++ to python. I have started working on it in python but I am not able to understand it that well. I have provided photos of the instructions and as well the c++ code I did. Thanks for your help if possible!

I need help converting this program from c++ to python. I havestarted working on it in python but I am not able tounderstand it that well. I have provided photos of the instructions and

Here is the copy-paste version of the code above:

#include

#include

using namespace std;

int main()

{

int integer;

ofstream outfile; //Part of extra credit

cout

cin >> integer;

cout

cout

cout

int previous = 0;

int currentVal = 1;

int temp = currentVal;

outfile.open("Fibonacci.txt"); //Part 1 of extra credit

for (int i = 0; i

{

cout

outfile

temp = currentVal;

currentVal = currentVal + previous;

previous = temp;

}

cout

system("pause");

return 0;

}

In the example program, we demonstrate using a for loop to calculate a simple Integer sequence. The Triangular number sequence follows the pattern 1, 3, 6, 10, 15, 21, 28, 36, 45, Our sample program calculates this pattern to a position determined by the value of the variable limit. Download the sample program, Sequences_For.cpp, create a project for it in Visual C+, and experiment to see how it works. Your Program The Fibonacci sequence is a numerical sequence that follows a simple pattern: 1,1, 2, 3, 5, 8, 13, 21, 34, 55, By definition, the first two numbers are 1 and 1, and each subsequent number is the sum of the previous two. For your program, you will ask the user to enter a number, n, and then calculate and display the values of the Fibonacci sequence to the nth position. You will probably need to use 4 integer variables for this lab: One will be used for the for loop control variable, as a counter. One will store the current value of the sequence (which you will print out) I recommend initializing this variable to 1. One will store the previous value of the sequence. I recommend initializing this to 0 One will be a temporary value that will allow you to properly update the other two. Print out the current value, calculate the next current value as the sum of the current and the previous, and then update the previous value obe equal to the old current value (you will need the temp to do this, since the old current value has since been replaced). Your output should look similar to the sample output. Submit your completed program through

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!