8.10. Exercises

8-1. Conditionals. Study the following code:

# statement A
if x > 0:
     # statement B
     pass
								elif x < 0:
     # statement C
     pass
								else:
    # statement D
    pass

# statement E

(a) Which of the statements above (A, B, C, D, E) will be executed if x < 0?

(b) Which of the statements above will be executed if x == 0?

(c) Which of the statements above will be executed if x > 0?

8-2. Loops. Write a program to have the user input three (3) numbers: (f)rom, (t)o, and (i)ncrement. Count from f to t in increments of i, inclusive of f and t. For example, if the input is f == 2, t == 24, and i == 4, the program would output: 2, 6, 10, 14, 18, 22.

8-3. range(). What argument(s) could we give to the range() built-in function if we wanted the following lists to ...

Get Core Python Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.