Question
Python Question 1: val_a = 0 val_b = 0 if val_a > val_b: val_a -= 1 val_b += 1 elif val_a < val_b: val_a -=
Python
Question 1:
val_a = 0
val_b = 0 if val_a > val_b: val_a -= 1 val_b += 1 elif val_a < val_b: val_a -= 2 val_b += 2 else: val_a -= 4 val_b += 4 if val_a < 0: val_a -= 8 val_b += 8 else: val_a -= 16 val_b += 16 print(val_a, val_b)
(Hint: value += 1 is the same as value = value+1. value -= 1 is the same as value = value-1.)
a) -8 8 b) -4 4 c) -20 20 d) -1 1 e) none of the above
Question 2
alice = ['remember', 'what', 'the', 'dormouse', 'said'] retake = alice[-2] + alice[4] + alice[-4] print(retake) a) dormouse b) dormousesaidwhat c) dormousedormousewhat d) Index Error: list index out of range e) none of the above
Question 3
songwriter = 'Grace Slick' print(songwriter[1:2]) a) G b) Grace c) Slick d) Grace Slick e) none of the above
Question 4
math_fact = [3, 'is', 'the first', ['odd'], 'prime'] print(math_fact[0] + math_fact[1] + math_fact[-1]) a) TypeError: unsupported operand type(s) for +: 'int' and 'str' b) 3isprime c) 3 is prime d) 3isodd e) none of the above
Question 5
import turtle s = turtle.Screen() t = turtle.Turtle() for i in range(3): t.forward(100) t.left(120) t.forward(100) t.right(120)
a) a zigzag line b) two triangles c) three sides of a square d) a triangle e) none of the
Question 6
def discrete_ops(x, y): for i in range(2): r = x%y q = x//y x += r y *= q return x+y a_num = discrete_ops(10,3) print(a_num)
a) 26 b) 23.0 c) 20 d) 22 e) none of the above
Question 7
warming = True highground = True if not (warming and highground): print('sun will rise') if not warming: print("many category5's") elif not warming and highground: print('no flooding')
a) no output b) sun will rise c) sun will rise many category5's d) sun will rise no flooding e) none of the above
Question 8
w0 = 'code' w1 = 'door' mismatches = 0 for letter in w0: if w0.count(letter) != w1.count(letter): mismatches += w1.count(letter) print(mismatches)
a) 3 b) 0 c) 1 d) 2 e) none of the above
Question 9
def test(aSeq, aVal): if aVal in aSeq: return aVal if [aVal] in aSeq: return [aVal] digits = [['1'], '1'] print(test(digits, 1))
a) 1 b) None c) 1, [1] d) no output e) none of the above
Question 10
def test(a_string, b_string): intersection = '' sym_diff = '' for letter in a_string: if letter in b_string: intersection += letter else: sym_diff += letter return intersection + sym_diff print(test('video', 'diva'))
a) None b) video c) '' d) videodiva e) none of the above
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started