Question

These are exercises in myprogramminglab for python and I think the simpler the code the better:...

These are exercises in myprogramminglab for python and I think the simpler the code the better:

1.An arithmetic progression is a sequence of numbers in which the distance (or difference) between any two successive numbers is the same. This in the sequence 1, 3, 5, 7, ..., the distance is 2 while in the sequence 6, 12, 18, 24, ..., the distance is 6.

Given the positive integer distance and the non-negative integer n, create a list consisting of the arithmetic progression between (and including) 1 and n with a distance of distance. For example, if distance is 2 and n is 8, the list would be [1, 3, 5, 7].

Associate the list with the variable arith_prog.

2. A geometric progression is a sequence of numbers in which each value (after the first) is obtained by multiplying the previous value in the sequence by a fixed value called the common ratio. For example the sequence 3, 12, 48, 192, ... is a geometric progression in which the common ratio is 4.

Given the positive integer ratio greater than 1, and the non-negative integer n, create a list consisting of the geometric progression of numbers between (and including) 1 and n with a common ratio of ratio. For example, if ratio is 2 and n is 8, the list would be [1, 2, 4, 8].

Associate the list with the variable geom_prog.

3.In the following sequence, each number (except the first two) is the sum of the previous two number: 0, 1, 1, 2, 3, 5, 8, 13, .... This sequence is known as the Fibonacci sequence.

Given the positive integer n create a list consisting of the portion of the Fibonacci sequence less than or equal to n. For example, if n is 6, then the list would be [0, 1, 1, 2, 3, 5] and if n is 1, then the list would be [0, 1, 1].

Associate the list with the variable fib.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

1. Program for Arthimetic Progression

# Read a positive integer for distance
distance = int(input("Enter a postive integer for distance: "))
# Read a positive integer for n
n = int(input("Enter a positive integer n: "))
count = 1
# Create a new list variable
arith_prog = [count]
# Using a while loop add the numbers in the arthimetic progression to the list
while count+distance <= n:
count = count + distance
arith_prog.append(count)
# Print the list
print ("The arthimetic progression is: " + str(arith_prog))

Output

В Python 3.6.4 Shell File Edit She Debug Options Window Help Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900

Program Screenshot

ArthimeticProgression.py - E:/Python/ArthimeticProgression.py (3.64) File Edit Format Run Options Window Help # Read a positi

2. Program for Geometric Progression

# Read a positive integer ratio
ratio = int(input("Enter a postive integer ratio greater than 1: "))
# Read a positive integer for n
n = int(input("Enter a positive integer n: "))
count = 1
# Create a new list variable
geom_prog = [count]
# Using a while loop add the numbers in the geometric progression to the list
while count + ratio <= n:
count = count * ratio
geom_prog.append(count)
# Print the list
print ("The geometric progression is: " + str(geom_prog))

Output

В Python 3.6.4 Shell File Edit She Debug Options Window Help Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900

Program Screenshot

GeometricProgression.py - E:/Python/GeometricProgression.py (3.6.4) File Edit Format Run Options Window Help # Read a positiv

3. Program for Fibonacci series

# Read a positive integer for n
n = int(input("Enter a positive integer n: "))
# Assign the first two terms
term1 = 0
term2 = 1
# Create a new list variable and add the first two terms
fib = [term1]
fib.append(term2)
# Using a while loop add the fibonacci terms into the list
while term1 + term2 <= n:
term3 = term1 + term2
term1 = term2
term2 = term3
fib.append(term3)
# Print the list
print ("The Fibonacci sequence is is: " + str(fib))

Output

В Python 3.6.4 Shell File Edit She Debug Options Window Help Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:04:45) [MSC v.1900

Program Screenshot

Fibonacci.py-Ε:/Python/Fibonacci.py (3.6.4) File Edit Format Run Options Window Help # Read a positive integer for n n - int

Add a comment
Know the answer?
Add Answer to:
These are exercises in myprogramminglab for python and I think the simpler the code the better:...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please code in Python. Python version 3.7.1 These are the hints and remarks for this question....

    Please code in Python. Python version 3.7.1 These are the hints and remarks for this question. In the following sequence, each number (except the first two) is the sum of the previous two number: 0, 1, 1, 2, 3, 5, 8, 13, This sequence is known as the Fibonacci sequence. Given the positive integer n create a list consisting of the portion of the Fibonacci sequence less than or equal to n. For example, if n is 6, then the...

  • c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8,...

    c++ fibonacci code using loops Here are 8 Fibonacci numbers: 1, 1, 2, 3, 5, 8, 13, 21 Note that the first Fibonacci number is 1, F(1) = 1 The second Fibonacci number is 1, i.e. F(2) = 1 Other Fibonacci numbers in the sequence is the sum of two previous Fibonacci numbers. For example F(3) = F(2) + F(1). In general F(n) = F(n-1) + F(n-2) Write a program to do the following tasks. User entries are shown in...

  • Question 3 Program Language C++ Problem 3 Fibonacci Numbers 10 points Fibonacci numbers are a sequence...

    Question 3 Program Language C++ Problem 3 Fibonacci Numbers 10 points Fibonacci numbers are a sequence of numbers where each number is represented by the sum of the two preceding numbers, starting with 0 and 1: 0, 1, 1, 2, 3, 5, 8, etc Write a program that repeatedly prompts the user for a positive integer and prints out whether or not that integer is a Fibonacci number. The program terminates when-I is entered. Create a method with the following...

  • Using R code only 4. The Fibonacci numbers are the sequence of numbers defined by the...

    Using R code only 4. The Fibonacci numbers are the sequence of numbers defined by the linear recurrence equation Fn F-1 F-2 where F F2 1 and by convention Fo 0. For example, the first 8 Fibonacci numbers are 1, 1, 2, 3, 5, 8, 13, 21. (a) For a given n, compute the nth Fibonnaci number using a for loop (b) For a given n, compute the nth Fibonnaci number using a while loop Print the 15th Fibonacci number...

  • I want this using while loop This using stringin python Use list or some thing in...

    I want this using while loop This using stringin python Use list or some thing in python Using list in python I want answer as soon as posdible E. Last Number time limit per test: 1 second memory limit per test: 256 megabytes input standard input output standard output You are given a sequence of positive integers aj, , 03, ... Print the last element of the sequence. Input The input consists of multiple lines. The i-th line contains a...

  • Arithmetic progression def arithmetic_progression(elems): An arithmetic progression is a numerical sequence so that the stride between...

    Arithmetic progression def arithmetic_progression(elems): An arithmetic progression is a numerical sequence so that the stride between each two consecutive elements is constant throughout the sequence. For example, [4, 8, 12, 16, 20] is an arithmetic progression of length 5, starting from the value 4 with a stride of 4. Given a list of elems guaranteed to consist of positive integers listed in strictly ascending order, find and return the longest arithmetic progression whose all values exist somewhere in that sequence....

  • PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a...

    PYTHON 3 - please show format Question 2. ) Use the Design Recipe to write a function yesOrNo which has no parameters. When called, it gets input from the user until the user types either 'yes' or 'no', at which point the function should return True if the user typed 'yes' and False if the user typed 'no'. Any other entries by the user are ignored and another value must be input. For example: Test Input Result print(yesOrNo()) hello blank...

  • The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13,...

    The Fibonacci sequence is the sequence of numbers: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, … The next number is found by adding up the two numbers before it. For example, the 2 is found by adding the two numbers before it (1+1). The 3 is found by adding the two numbers before it (1+2). The 5 is found by adding the two numbers before it (2+3), and so on! Each number in the sequence is called...

  • write the solution of the program by python 3 language : I need the program using...

    write the solution of the program by python 3 language : I need the program using list or string or loops (while and for) or if,elif,else : Alex got a sequence of n integers a1,a2,…,an as a birthday present. Alex doesn't like negative numbers, so he decided to erase the minus signs from all negative numbers. As a result, he got a sequence of non-negative numbers. Print the resulting sequence. For example, if the sequence is  1, 5, -3, 4,...

  • 1- What is a geometric progression? Give an example to justify your answer. 2- What is...

    1- What is a geometric progression? Give an example to justify your answer. 2- What is an arithmetic progression? Give an example to justify your answer. 3- What is a recurrence relation. 4- What isthe method that we might use to solve recurrence relations ? 5- What is the difference between a geometric progression and geometric serie. Justify your answer.

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT