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
sp2606 [1]
3 years ago
13

A python script to print fibonacci series first 20 elements

Computers and Technology
1 answer:
madreJ [45]3 years ago
5 0

Answer:

   nterms =20

   # first two terms

   n1, n2 = 0, 1

   count = 0

   # check if the number of terms is valid

   if nterms <= 0:

      print("Please enter a positive integer")

   elif nterms == 1:

      print("Fibonacci sequence upto",nterms,":")

      print(n1)

   else:

      print("Fibonacci sequence:")

      while count < nterms:

          print(n1)

          nth = n1 + n2

          # update values

          n1 = n2

          n2 = nth

          count += 1

Explanation:

Here, we store the number of terms in nterms. We initialize the first term to 0 and the second term to 1.

If the number of terms is more than 2, we use a while loop to find the next term in the sequence by adding the preceding two terms. We then interchange the variables (update it) and continue on with the process.

<em>output:</em>

Fibonacci sequence:

0

1

1

2

3

5

8

You might be interested in
Our Client, a renowned trading company, suffered a sudden, devastating power outage that caused their server to cease functionin
Norma-Jean [14]

Answer:

Explanation:

I will consult the following strategies:

Step 1: Being a discerning consultant I should be knowing what exactly has caused the drive to get corrupted.

Step 2: After examining the current state of the hard drive I will explain the actual problem to the client in a very lucid and eloquent manner whether it is feasible to retrieve the lost data or it is beyond repair.

Step 3: Identify a solution to the problem with things at my disposal(finding a right tool).

Step 4: apply the solution found to retrieve the data from the hard drive.

Step 5: submitting the retrieved data from the corrupt drive to the customer and advocating them the preventive measures for future reference.

The above five steps will work perfectly to resolve the issue faced if followed with great care and being heedful of the situation at hand.

6 0
3 years ago
The Yuba College Library would like a program to calculate patron fines for overdue books. Fines are determined as follows: Pape
mestny [16]

Answer:

Explanation:

The following Python code creates all of the necessary functions in order to request and validate all of the inputs from the user. Once everything is entered and validated it calculates the total fee and outputs it to the user. Also calls the entire class at the end using a test variable...

class Customer:

   library_card = 0

   patrons_name = ""

   patrons_address = ""

   type_of_book = ""

   book_title = ""

   days_overdue = 0

   fee = 0.0

   book_list = ['paperback regular', 'paperback best seller', 'magazine', 'hardcover']

   def __init__(self):

       self.library_card = self.get_library_card()

       self.patrons_address = input("Patron's Address: ")

       self.book_title = input("Book Title: ")

       self.type_of_book = self.get_type_of_book()

       self.days_overdue = float(self.get_days_overdue())

       self.calculate_total()

       print("Your total Fee is: " + str(self.fee))

   def get_library_card(self):

       library_card = int(input("Enter 4-digit library card number: "))

       if (type(library_card) == type(0)) and (len(str(library_card)) == 4):

           return library_card

       else:

           print("Invalid Card number:")

           self.get_library_card()

   def get_type_of_book(self):

       type_of_book = input("Type of Book 1-4: ")

       if (int(type_of_book) > 0) and (int(type_of_book) <= 4):

           return int(type_of_book)

       else:

           print("Invalid Type")

           self.get_type_of_book()

   def get_days_overdue(self):

       days_overdue = input("Number of Days Overdue: ")

       if int(days_overdue) >= 0:

           return days_overdue

       else:

           print("Invalid number of days")

           self.get_days_overdue()

   def calculate_total(self):

       if self.type_of_book == 1:

           self.fee = 0.20 * self.days_overdue

           if self.fee > 8:

               self.fee = 8

       elif self.type_of_book == 2:

           self.fee = 0.50 * self.days_overdue

           if self.fee > 15:

               self.fee = 15

       elif self.type_of_book == 3:

           self.fee = 0.25 * self.days_overdue

           if self.fee > 5:

               self.fee = 5

       else:

           self.fee = 0.30 * self.days_overdue

           if self.fee > 23:

               self.fee = 23

test = Customer()

5 0
2 years ago
How do I write a good personal narrative pls help im struggling very hard rn.​
statuscvo [17]

Answer: Find out which starter makes your partner most interested in reading your story.

1. Start with action or dialogue.

2. Ask a question or set of questions.

3. Describe the setting so readers can imagine it.

4. Give background information that will interest readers.

5. Introduce yourself to readers in a surprising way.

Explanation:

4 0
3 years ago
Set-In-Order includes making changes to the layout of the area.A) TrueB) False
Bogdan [553]

Answer:

A) True

Explanation:

Set-In-Order is part of a 5S system approach of making a workplace to be well arranged so there will be smooth operation of employees and working conditions.

Set-In-Order specifically deals with entities in the workplace apparently labeled after being well arranged in their respective places.

Hence, it is TRUE that Set-In-Order includes making changes to the layout of the area.

7 0
3 years ago
Hurrryyyy it’s either a or c
Veseljchak [2.6K]

Answer and Explanation:

I believe its A. Modularity enables multiple programmers to work on a program at the same time..

Let me know if I'm wrong..

4 0
3 years ago
Other questions:
  • Writenames of eight output device.​
    8·1 answer
  • Where (what memory location) is the data read from for the following code:
    12·1 answer
  • Which command displays the contents of the NVRAM?
    13·1 answer
  • Of the following online activities, identify the TWO that are most likely to be affected by bandwidth quality
    11·1 answer
  • Declare a typedef struct named jumper_t that will have four parts: character array name that is 16 in length, double array of tr
    12·1 answer
  • Which of these lines of code will increment a variable?
    11·1 answer
  • Which feature helps an edit-test-bug cycle work faster in the python programming language?
    15·2 answers
  • You text file begins with the following rows. The pattern is a description of the item to be repaired, its color, and the issue.
    14·1 answer
  • You have been asked to investigate a web server for possible intrusion. You identify a script with the following code. What lang
    10·1 answer
  • The RGB value below produces a shade of purple. What does the number 175
    15·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!