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
Katyanochek1 [597]
3 years ago
7

Problem 6. (Fibonacci Number) Write a program fibonacci.py that accepts n (int) as command-line argument, and writes to standard

output the nth number from the Fibonacci sequence (1, 1, 2, 3, 5, 8, 13, . . . ).
Computers and Technology
1 answer:
77julia77 [94]3 years ago
7 0

Answer:

  1. import sys
  2. def fibonacci(n):
  3.    if(n == 0 or n == 1):
  4.        return n  
  5.    else:
  6.        return fibonacci(n - 2) + fibonacci(n-1)
  7. num = int(sys.argv)  
  8. output = ""
  9. for i in range(1, num+1):
  10.    output += str(fibonacci(i)) + " "  
  11. print(output)

Explanation:

Firstly, we import sys module as we need to accepts n as command line argument (Line 1).

Next, create a function fibonacci takes take one input n (Line 3). If the n is zero or one, return the n itself (Line 4-5). Otherwise, the program shall run the recursive call to the fibonacci function itself by putting n-2 and n-1 as function argument, respectively (Line 6-7).

After that, use the sys.argv to get the command line argument and assign the value to num (Line 9).

Use a for loop to generate the output string by progressively calling the fibonacci function and join the return result to the output string (Line 12-13).

At last print the output string (Line 15).

You might be interested in
What are the most common types of cables in a network?
Maru [420]

the most common are twisted pair, coaxial, Ethernet cross over, and fiber optic.

4 0
3 years ago
If we assume the modern view of existential import, why is the following syllogism invalid? No computer is made of clay. All com
Papessa [141]

Answer:

<u>because the conclusion is not in agreement with the two premises.</u>

Explanation:

<em>Remember</em>, the term<u> syllogism</u> refers to the form of reasoning that draws its conclusion based on the stated premises. In other words, a conclusion is reached if it satisfies <em>all or part </em>of the premises.

In this case, the statement "No computer is made of clay" and  "All computers are electronic devices" should be inferred to mean, <em><u>No </u></em><em>electronic devices are made of clay" </em>not<em> </em><em>"Some electronic devices are not made of clay," </em>since the two premises neither suggest that electronic devices are made from clay.

5 0
3 years ago
What is the best resource to learn python?
7nadin3 [17]

Answer:

prolly a snake expert

Explanation:

they know snakes

4 0
3 years ago
Read 2 more answers
How did mechanical clocks assist in completing work? How was work done previously?
lozanna [386]

Answer

Timekeeping has been a part of society since Ancient Egypt. The use of spring-powered mechanisms allowed clocks to be made smaller ... Essentially, the church bells and the mechanical clock now became the monitor of the working day.

Explanation:

4 0
3 years ago
Two forms of compression are lossy and lossless. State giving reasons which
Helen [10]

Answer:

(i) When transmitting a draft manuscript for a book, the lossless compression technique is most suitable because after decompression, the data is rebuilt and restored in its form as it was from where it originated

(ii) When transmitting a video recording which you have made of the school play, a lossy compression technique is most suitable because the large size of video files require the increased data carrying capacity which is provided by the lossy transmission technique. The quality of the video can be reduced without affecting the message intended to be delivered

Explanation:

4 0
3 years ago
Other questions:
  • divide the input array into thirds (rather than halves), recursively sort each third, and finally combine the results using a th
    15·1 answer
  • A drowsy cat spots a flowerpot that sails first up and then down past an open window. The pot is in view for a total of 0.50 sec
    13·1 answer
  • How do you know if a remote host is alive or not?
    5·1 answer
  • In Python, arrays are usually reserved for
    12·1 answer
  • What do character formats do for your document's message??
    14·2 answers
  • Which of the following describes ETL? a) A process that transforms information using a common set of enterprise definitions b) A
    14·1 answer
  • Cisco has created a proprietary layer 2 protocol used to manage VLAN configuration between switches called:________a. VLAN Confi
    11·1 answer
  • Based on the screenshot below which letter do you select to sort the items in an alphabetical order?
    9·1 answer
  • Assume that the message M has to be transmitted. Given the generator function G for the CRC scheme, calculate CRC. What will be
    15·1 answer
  • Which is a benefit of peer-to-peer networking?
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!