What's the Difference?

The questions below are due on Friday June 21, 2024; 10:00:00 PM.
 
You are not logged in.

Please Log In for full access to the web site.
Note that this link will take you to an external site (https://shimmer.mit.edu) to authenticate, and then you will be redirected back to this page.

1) Part 1

Consider the following snippets from programs:

# piece A
print(something)
# piece B
print("something")

Briefly describe the differences, if any, between these two pieces of code and how Python evaluates them.

Formatting Help

2) Part 2

Consider the following snippets from programs:

# piece A
if condition1:
    print('meow')
if condition2:
    print('woof')
else:
    print('quack')
# piece B
if condition1:
    print('meow')
elif condition2:
    print('woof')
else:
    print('quack')
# piece C
if condition1:
    print('meow')
else:
    if condition2:
        print('woof')
    else:
        print('quack')

Briefly describe the differences, if any, between these three pieces of code and how Python evaluates them.

Formatting Help

3) Part 3

Consider the following snippets from programs:

# piece A
a = [1]
b = a
a = a + [7]
print(a)
print(b)
# piece B
a = [1]
b = a
a.append(7)
print(a)
print(b)

Briefly describe the differences, if any, between these two pieces of code and how Python evaluates them.

Formatting Help

Next Exercise: Conditionals

Back to exercises