Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem Carefully read the problem specification below:Problem SpecificationWrite a function named reverse _ arithmetic _ sequence that has three parameters, first, difference , terms. Your

ProblemCarefully read the problem specification below:Problem SpecificationWrite a function named reverse_arithmetic_sequence that has three parameters, first,difference, terms. Your code should work with data ofany datatype provided as arguments.The function should:1Validate the provided parameter values (see specification below)2Generate the sequence using the algorithm below3Return the generated sequence as a list.You will need to do some validation on the parameters provided:All parameter values must be integers(in either int or str format). If any of the parameters do not hold integer values, the function should return None.A valid firstvalue must be between 50 and 200(inclusive).A valid differencevalue must be greater than 1 and less than or equals to 10.A valid terms value must be between 5 and 100(inclusive).If any of the three restrictions above are not met, the function should return False.Algorithm1Generate a list of numbers that begins with thefirst value. Each value in the list should be an integer (datatype).2Each subsequent value in the list is calculated by taking the previous value and subtracting the difference to it (refer to the test cases below as examples).3Thenumber of items in the list should be equal to the value of terms.Skeleton Codedef reverse_arithmetic_sequence(first,difference,terms):""" Test cases:>>> reverse_arithmetic_sequence(60,2,6)[60,58,56,54,52,50]>>> reverse_arithmetic_sequence(100,5,10)[100,95,90,85,80,75,70,65,60,55]>>> reverse_arithmetic_sequence('50',2,5)[50,48,46,44,42]>>> reverse_arithmetic_sequence(73,'3',7)[73,70,67,64,61,58,55]>>> reverse_arithmetic_sequence(50,2,'5')[50,48,46,44,42]>>> print(reverse_arithmetic_sequence(73.5,4,10)) None>>> print(reverse_arithmetic_sequence(85,4.6,10)) None>>> print(reverse_arithmetic_sequence(100,4,10.3)) None>>> reverse_arithmetic_sequence(20,4,10) False>>> reverse_arithmetic_sequence(300,4,10) False>>> reverse_arithmetic_sequence(62,1,10) False>>> reverse_arithmetic_sequence(92,12,10) False>>> reverse_arithmetic_sequence(63,4,3) False>>> reverse_arithmetic_sequence(73,5,231) False""" # TODO: Your code here# Call the code to run the doctestsimport doctestdoctest.testmod(verbose=True)

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions