[Back to Lab 4] [Back to CS 115 schedule]
As you work through this section, be sure that you really understand each of the programs, and call for help if you don't!
def main():
x = 7
if x < 0:
print('negative')
if x > 0:
print('positive')
main()
Then click "Visualize execution."
if x < 0:
print('negative')
else:
print('non-negative')
Then click "Visualize execution."def main():
num = 5 # change this value
if num == 0:
num += 2
print('Your value is now ', num, '.', sep="")
else:
num += 4
print('Your value is now ', num, '.', sep="")
if num > 0:
num -= 4
print('Your value is now ', num, '.', sep="")
main()
if num == 0:
num += 2
print('Your value is now ', num, '.', sep="")
if num < 0:
num += 4
print('Your value is now ', num, '.', sep="")
else:
num -= 4
print('Your value is now ', num, '.', sep="")
if num == 0:
num += 2
print('Your value is now ', num, '.', sep="")
elif num < 0:
num += 4
print('Your value is now ', num, '.', sep="")
if num > 0:
num -= 4
print('Your value is now ', num, '.', sep="")
if num == 0:
num += 2
print('Your value is now ', num, '.', sep="")
elif num < 0:
num += 4
print('Your value is now ', num, '.', sep="")
else:
num -= 4
print('Your value is now ', num, '.', sep="")
line = 1
for i in range(1, 4):
for j in range(1, 5):
print('Line ', line, ': (', i, ', ', j, ')', sep="")
line += 1
Try to predict what this loop will do. Answer Questions 9-12 in your writeup.
Then use the tutor to step through this loop and check your work.