Question

In: Computer Science

Define and test a function myRange. This function should behave like Python’s standard range function, with...

Define and test a function myRange. This function should behave like Python’s standard range function, with the required and optional arguments, but it should return a list. Do not use the range function in your implementation!

Study Python’s help on the range to determine the names, positions, and what to do with your function’s parameters. Use a default value of None for the two optional parameters. If these parameters both equal None, then the only provided argument should be considered the stop value, and the start value should default to 0. If just the third parameter equals None, then the function has been called with a start and stop value. Thus, the first part of the function’s code establishes what the values of the parameters are or should be. The rest of the code uses those values to build a list by counting up or down.

An example of the range function with only one argument provided is shown below:

print(myRange(10))

[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Solutions

Expert Solution

def myRange(stop,start=0,step=0):
lt=[]
if start!=None: #start is not a none value
i=start
else:
i=0 #else assign i=0
if step==None or step>=0:
#for count up
while i<stop: #range upto stop value
lt.append(i) #add numbers o the list
if step!=None and step!=0: # if step value is specified any value without None or 0 then add it to i variable.
i+=step
else:
i+=1 #default value for step value is one, so add 1 to each iteration
else:
#count down
while i>=stop:
lt.append(i)
if step!=None and step!=0:
i=i+step
return lt
print(myRange(12,0,-1)) #print the list of values with specified range

output:
for print(myRange(0,12,-1))

for print(myRange(12,0))

for print(myRange(12,None,None))

for print(myRange(12))


Related Solutions

Define standard deviation, index of dispersion, and range.
Define standard deviation, index of dispersion, and range.
No other code on this website works. Define a function drawCircle. This function should expect a...
No other code on this website works. Define a function drawCircle. This function should expect a Turtle object, the coordinates of the circle’s center point, and the circle’s radius as arguments. The function should draw the specified circle. The algorithm should draw the circle’s circumference by turning 3 degrees and moving a given distance 120 times. Calculate the distance moved with the formula 2.0 × π × radius ÷ 120.0. Define a function main that will draw a circle with...
Define a function drawCircle. This function should expect a Turtle object, the coordinates of the circle’s...
Define a function drawCircle. This function should expect a Turtle object, the coordinates of the circle’s center point, and the circle’s radius as arguments. The function should draw the specified circle. The algorithm should draw the circle’s circumference by turning 3 degrees and moving a given distance 120 times. Calculate the distance moved with the formula 2.0 × π × radius ÷ 120.0. Define a function main that will draw a circle with the following parameters when the program is...
Define a function drawCircle. This function should expect a Turtle object, the coordinates of the circle’s...
Define a function drawCircle. This function should expect a Turtle object, the coordinates of the circle’s center point, and the circle’s radius as arguments. The function should draw the specified circle. The algorithm should draw the circle’s circumference by turning 3 degrees and moving a given distance 120 times. Calculate the distance moved with the formula 2.0 × π × radius ÷ 120.0. Define a function main that will draw a circle with the following parameters when the program is...
the range versus angle graph should be a parabola since its the visualization of the function...
the range versus angle graph should be a parabola since its the visualization of the function in between a 0 degree minimum angle an a 90 degrees maximum angle true or false? explain why please
The Canadian government would like to test the hypothesis that the standard deviation for the hourly...
The Canadian government would like to test the hypothesis that the standard deviation for the hourly wage for men is equal to the standard deviation for the hourly wage for women. The sample size for men is 11 with sample standard deviation 2.25 and the sample size for women is 9 with standard deviation 3.75. Assume that hourly wages are normally distributed. a) What are the parameters of interest? b) Define the null and alternative hypothesis. c) What is the...
The federal government would like to test the hypothesis that the standard deviation for the age...
The federal government would like to test the hypothesis that the standard deviation for the age of men filing for Social Security is higher than the standard deviation for the age of women. The following table summarizes sample statistics from each population. Women Men Sample standard deviation 2.4 years 3.4 years Sample size 24 20 The test statistic for this hypothesis test would be ________. 2.01 4.87 5.60 7.74 A chocolate chip cookie producer claims that its cookies average 3...
Sony would like to test the hypothesis that the standard deviation for the age of PlayStation...
Sony would like to test the hypothesis that the standard deviation for the age of PlayStation users is higher than the standard deviation for the age of Xbox users. the following table summarizes sample statistics from each population. PlayStation Xbox Sample Standard Deviation 4.3 years 4.9 years Sample size 25 28 using a= 0.05, the conclusion for this hypothesis test would be that because the test statistics is A) more than the critical value, we reject the null hypothesis and...
Define the equivalence partitions and give suitable test cases for the following: Zip codes: Range from...
Define the equivalence partitions and give suitable test cases for the following: Zip codes: Range from 00600 to 98000 inclusive. States: AL (Alabama) to WY (Wyoming) Last Name: One through twelve characters (alphabetic, space and hyphen) User ID: Eight characters, at least two of which are not alphabetic (numeric, special characters) For full credit, you should give one test case for each equivalence partition defined by you, even if it is possible to cover more than one partitions in one...
Define the term melting point range
Define the term melting point range
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT