1. Engineering
  2. Computer Science
  3. create a script for this lab the body of the...

Question: create a script for this lab the body of the...

Question details

Create a script for this lab. The body of the script shall call functions that print out the values 1, 32, 63, 94, 125, 156, 187, 218, 249, 280, using different looping specifications in each function. Each of these should use a loop to call the print function multiple times. A separate call to the print function shall output each individual numerical value. So, it will use ten calls to print to output the ten values.

Check Level

  • The values for any given loop shall be printed on a single line, separated by spaces.
  • One of the most obvious ways to structure the for-range function will use all three parameters of range.
  • Add another function to print out the ten numerical values. This time, use the for loop with range. However, in the "second" for loop, the call to range will have only a single argument.

A couple notes about the fourth loop, the for loop with one-parameter range:

  • This should not use the if statement to skip values.
  • This should not use a list of values.
    You did that already in the first for loop.
  • This fourth loop shall calculate the values.
    Do not add the increment to a separate variable. You did that already in the while loop.

Sample Output

Using the while loop:
1 32 63 94 125 156 187 218 249 280

Using the for loop with a list:
1 32 63 94 125 156 187 218 249 280

Using the for loop with range, three argument:
1 32 63 94 125 156 187 218 249 280

Using the for loop with range, one argument:
1 32 63 94 125 156 187 218 249 280

Plus Level

  • The output from each loop shall appear separated by comma-space. There shall be no comma following the final value.
  • This is an example of a common, slightly more advanced programming problem, which has been called the fencepost problem. For more information, look at the Wikipedia article.
  • The plus points are awarded for implementing the fencepost algorithm from scratch. Using the str method join will not earn plus points.
  • See if you can accomplish this without using any additional variables in the code with the loops.
  • Finally, you should not use the if statement in the implementation. Nor should you use a second while statement as a "hidden" if statement.

Sample Output

Using the while loop:
1, 32, 63, 94, 125, 156, 187, 218, 249, 280

Using the for loop with a list:
1, 32, 63, 94, 125, 156, 187, 218, 249, 280

Using the for loop with range, three argument:
1, 32, 63, 94, 125, 156, 187, 218, 249, 280

Using the for loop with range, one argument:
1, 32, 63, 94, 125, 156, 187, 218, 249, 280

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution