I\'m given the following python 3 code. I need to run it so everything prints tr
ID: 3876361 • Letter: I
Question
I'm given the following python 3 code. I need to run it so everything prints true. For the most part i've fixed it but can't figure out the rest. Help.
print(" # -- part 1 -- #")
# Modify the variable values so that all of the
# `print` statements print "True".
zero = 0
> two = [5, 4, 3, 2, 1]
three = ["I" ,"love", "Python!"]
four = [["P", "y", "t", "h", "o", "n"],["i", "s"],["h", "u", "r", "d"]]
five = {"happy":"birthday","fish":"chips", "test":"one"}
six = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
days = ("Fri", "Sat", "Wed")
x, y, seven = days
# DO NOT CHANGE ANYTHING IN THIS SECTIOn #
# --BEGIN -------------------------------- #
print("zero: {}".format(zero == 0))
print("one: {}".format(one > 22))
print("two: {}".format(len(two) == 5))
print("three: {}".format(three[2] == "Python!"))
print("four: {}".format(four[0][5] == 'n' and four[0][0] == "P" and four[2][1] == "u"))
print("five: {}".format(five.get("fish") == "chips"))
print("five: {}".format(len(five) == 3))
print("six: {}".format(len(six & {2,5,7}) == 2))
print("seven: {}".format(seven == "Wed"))
# --END------------------------------------- #
print(" # -- part 2 -- #")
# Replace the right-hand side of the assignment below
# so that the print statements below print "True"
value = [1,2,3,4,5]
# DO NOT CHANGE ANYTHING IN THE SECTION BELOW #
# --BEGIN -------------------------------- #
if type(value) is list:
print(True)
else:
print(False)
for x in value:
if not type(x) is int:
print(False)
else:
print(True)
num = 0
while num < value[2]:
print(True)
num += 1
for y in range(value[3]):
if y in value:
print(False)
try:
value[5] = "Cat"
while True:
print(False)
except IndexError:
print(True)
try:
assert value[3] == -1
except AssertionError:
print(True)
# --END------------------------------------- #
Explanation / Answer
Solution Program: I have mentioned the changes that I have made in the comments.
print(" # -- part 1 -- #")
# Modify the variable values so that all of the
# `print` statements print "True".
zero = 0
> two = [5, 4, 3, 2, 1]
three = ["I" ,"love", "Python!"]
four = [["P", "y", "t", "h", "o", "n"],["i", "s"],["h", "u", "r", "d"]]
five = {"happy":"birthday","fish":"chips", "test":"one"}
six = {1, 2, 3, 4, 5, 6, 8, 9, 10} #removed 7
days = ("Fri", "Sat", "Wed")
x, y, seven = days
# DO NOT CHANGE ANYTHING IN THIS SECTIOn #
# --BEGIN -------------------------------- #
print("zero: {}".format(zero == 0))
print("one: {}".format(one > 22))
print("two: {}".format(len(two) == 5))
print("three: {}".format(three[2] == "Python!"))
print("four: {}".format(four[0][5] == 'n' and four[0][0] == "P" and four[2][1] == "u"))
print("five: {}".format(five.get("fish") == "chips"))
print("five: {}".format(len(five) == 3))
print("six: {}".format(len(six & {2,5,7}) == 2))
print("seven: {}".format(seven == "Wed"))
# --END------------------------------------- #
print(" # -- part 2 -- #")
# Replace the right-hand side of the assignment below
# so that the print statements below print "True"
value = [1,2,3,0,5] #changed 4 with 0
# DO NOT CHANGE ANYTHING IN THE SECTION BELOW #
# --BEGIN -------------------------------- #
if type(value) is list:
print(True)
else:
print(False)
for x in value:
if not type(x) is int:
print(False)
else:
print(True)
num = 0
while num < value[2]:
print(True)
num += 1
for y in range(value[3]):
if y in value:
print(False)
try:
value[5] = "Cat"
while True:
print(False)
except IndexError:
print(True)
try:
assert value[3] == -1
except AssertionError:
print(True)
Output:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.