1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Novosadov [1.4K]
3 years ago
13

We will pass in a value N. Write a program that outputs the complete Fibonacci sequence for N iterations. Important: If N is 0,

then we expect to get an output of 0. If N=1 then we expect 0, 1 etc.
Computers and Technology
1 answer:
jasenka [17]3 years ago
3 0

Answer:

The program written in Python is as follows

def fibonac(N):

    series = ""

    for i in range(0,N+1):

         series = series + str(i) + ","

   return series[:-1]

N = int(input("Number: "))

print(fibonac(N))

Explanation:

This line defines the function fibonac

def fibonac(N):

This line initializes variable "series" to an empty string

    series = ""

This line iterates through the passed argument, N

    for i in range(0,N+1):

This line determines the Fibonacci sequence

         series = series + str(i) + ","

Lastly, this line returns the Fibonacci sequence

   return series[:-1]

The main starts here

The firs line prompts user for input

N = int(input("Number: "))

This line prints the Fibonacci sequence

print(fibonac(N))

You might be interested in
Write a program that reads a stream of integers from a file and writes only the positive numbers to a second file. The user shou
borishaifa [10]

Answer:

See explaination for thr program code.

Explanation:

import java.io.File;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.FileWriter;

import java.io.IOException;

import java.io.OutputStream;

import java.io.PrintWriter;

import java.util.Scanner;

public class ReadWriteInt

{

public static void main(String args[]) throws IOException

{

Scanner input=new Scanner(System.in);

System.out.println("Enter the name of the input file:");

String inputFile=input.next();

System.out.println("Enter the name of the output file:");

String outputFile=input.next();

File fin=new File(inputFile);

File fout=new File(outputFile);

//print error, if input file does not exist

if(!fin.exists())

{

System.out.println("Error:Input file does not exist");

System.exit(0);

}

//print error, if output file does not exist

if(!fout.exists())

{

System.out.println("Error:output file does not exist");

System.exit(0);

}

//input stream to read

Scanner read=new Scanner(fin);

OutputStream os=new FileOutputStream(fout);

//output stream to write

PrintWriter write=new PrintWriter(os,true);

//read from input file until there are no numbers

while(read.hasNextLine())

{

String num=read.nextLine();

//convert the string into number

int number=Integer.parseInt(num);

//if the number is positive , write it to out put file

if(number>=0)

{

write.println(number);

System.out.println(number);

}

}

System.out.println("Positive numbers are copied successfully");

}

}

Please check attachment for screenshot and output

5 0
3 years ago
The 10 and 2 o'clock hand position on the steering wheel is no longer recommended because _____.
lesantik [10]
C.

Experts say with more compact steering wheels, the old 10 and 2 puts arms in path of the air bag. Resulting in bodily harm if it deployed.
5 0
3 years ago
Click to review the online content. Then answer the question(s) below, using complete sentences. Scroll down to view additional
Serggg [28]

Answer:

Alumni Groups

Business Organizations

Explanation: i made a 100 on lesson

7 0
3 years ago
To combine concepts or ideas into a whole is called
Vinil7 [7]
A. synthesizing im pretty sure :)
3 0
3 years ago
Read 2 more answers
Question #4
Igoryamba

Answer:

The y-intercept is going to fall by -2 but the x-intercept will run +5

Explanation:

Becuase the derivative of the equation causes this when plugged into the formula

6 0
2 years ago
Other questions:
  • 1. What is the difference between a learner’s license and an operator’s license?
    10·1 answer
  • Which device can be installed on the edge of your network to allow multiple remote users to connect securely to your internal en
    9·1 answer
  • Josh wants to convey his best wishes to johnathin for a meeting schedualed later diring the day. Which business documented would
    7·1 answer
  • what tool can a student use to make sure his or her work paper does not take credit for someone else's work ?
    5·1 answer
  • If you have two redo log groups with four members each, what’s the optimal number of disks you need to provide appropriate prote
    5·1 answer
  • Which of the following statements is NOT true about url extension?
    10·2 answers
  • Why do we need operating systems?
    7·1 answer
  • Tasks you can perform online include which of the following?
    13·1 answer
  • Which type of protocol provides a way to transfer files from one computer to another over any tcp/ip network, such as a lan or t
    14·1 answer
  • _____ allows a function or operator to perform different tasks depending on the types of the arguments or operands. Group of ans
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!