[SOLVED] SOLVED:Computer Science 222 Laboratory 2 – Practice Using Loops and Doing Arithmetic

25.00 $

Programming resource
Digital learning resource
Category:
Practical programming resource
Suitable for guided study and reference
Tutor guidance available when needed

Description

5/5 - (1 vote)

Think about the human users of your programs (documentation). Develop simple Python programs that do input, produce output and do arithmetic. Directed Activities: 1. Clear a space on your desk and write the values of the variables as the code executes and the outputs that will be generated from the following code segments. a. for i in range(8): print i i = 0 output = 0 i = 1 output = 1 i = 2 output = 2 i = 3 output = 3 i = 4 output = 4 i = 5 output = 5 i = 6 output = 6 i = 7 output = 7 b. for i in [1, 3, 9]: print i i = 1 output = 1 i = 3 output = 3 i = 9 output = 9 c. for i in range(-1): print i nothing d. sum = 0 for i in range(5): sum = sum + i print sum i = 0 output = 1 i = 1 output = 2 i = 2 output = 3 i = 3 output = 4 i = 4 output = 5 e. power = 2 for i in [2, 4, 6]: print i ** power i = 2 output = 4 i = 4 output = 16 i = 6 output = 36 f. difference = 0 for i in [1, 8, -2, 15, 0]: difference = difference – i print difference i = 1 output = -1 i = 8 output = -9 i = -2 output = -7 i = 15 output = -22 i = 0 output = -22 g. product = 1 for i in range(4): product = product * i print product i = 0 output = 0 i = 1 output = 0 i = 2 output = 0 i = 3 output = 0 h. product = 1 for i in [1, 3, 5]: product = product * i print product i = 1 output = 1 i = 3 output = 3 i = 5 output = 15 2. Log on to the computer using your Cougars account information. Open your WebCT account for this course (labeled CSCI 222-L0#). After completing each of the following exercises, demonstrate your code for the instructor. 3. Create a Python test file. Create a Python program called loopPractice.py. This program should contain the code for the eight loops above. The program should print in the format: Loop A:

Resource details

Understand the Task Before You Use the Resource

Review the requirements, identify the programming concepts involved, study the implementation and test your understanding with your own examples and modifications.