Podcast
Questions and Answers
What will be the output of the following code?
a = 5
b = 'b'
c = True
print("The answer is...", end=' ')
if a != 10:
print("A", end=' ')
elif b == 'b':
print("B", end=' ')
else:
print("C", end=' ')
z = c and bool(a)
print(z, end=' ')
d = a ** 3 + 25 % 3 - 12 // 5
print(d)
What will be the output of the following code?
a = 5
b = 'b'
c = True
print("The answer is...", end=' ')
if a != 10:
print("A", end=' ')
elif b == 'b':
print("B", end=' ')
else:
print("C", end=' ')
z = c and bool(a)
print(z, end=' ')
d = a ** 3 + 25 % 3 - 12 // 5
print(d)
The answer is... A True 132
What will be the output of the following code?
n = 1
p = "A"
while n < 10:
p += p
n += 3
print(n, p)
What will be the output of the following code?
n = 1
p = "A"
while n < 10:
p += p
n += 3
print(n, p)
10 AAAAAAAAAA
What will be the output of the following code?
a = True
b = bool('False')
c = 5 > 8
d = a and b and c
e = not a or not (b and c)
print(d, e)
What will be the output of the following code?
a = True
b = bool('False')
c = 5 > 8
d = a and b and c
e = not a or not (b and c)
print(d, e)
False True
What will be the output of the following code?
mystrs = ['Good Bull', 'Whoop', 'Hullabaloo', 'Howdy', "Gig 'em", 'Aggies']
mynums = [3, 5, 4, 1, 2]
for num in mynums:
print(mystrs[num], end=' ')
What will be the output of the following code?
mystrs = ['Good Bull', 'Whoop', 'Hullabaloo', 'Howdy', "Gig 'em", 'Aggies']
mynums = [3, 5, 4, 1, 2]
for num in mynums:
print(mystrs[num], end=' ')
Signup and view all the answers
What will be the output of the following code?
mylist = []
for i in range(5):
mylist.append(i ** 2)
print(mylist[-3:])
What will be the output of the following code?
mylist = []
for i in range(5):
mylist.append(i ** 2)
print(mylist[-3:])
Signup and view all the answers
What will be the output of the following code?
x = 5 / 5
print(x)
What will be the output of the following code?
x = 5 / 5
print(x)
Signup and view all the answers
What will be the output of the following code?
mystr = 'The quick brown fox jumped over the lazy dog'
print(mystr[:3], end=' ')
if mystr == 'q':
if 'fox' in mystr:
print('fox', end=' ')
else:
print('dog', end=' ')
if mystr[-5] != 'z':
print('jumped', end=' ')
else:
print('hopped', end=' ')
elif 'x' in mystr:
if 'white' in mystr:
print('white mouse', end=' ')
else:
print('brown cow', end=' ')
if 'y' not in mystr:
print('sat', end=' ')
else:
print('dropped', end=' ')
else:
print(mystr[4:26], end=' ')
print('down')
What will be the output of the following code?
mystr = 'The quick brown fox jumped over the lazy dog'
print(mystr[:3], end=' ')
if mystr == 'q':
if 'fox' in mystr:
print('fox', end=' ')
else:
print('dog', end=' ')
if mystr[-5] != 'z':
print('jumped', end=' ')
else:
print('hopped', end=' ')
elif 'x' in mystr:
if 'white' in mystr:
print('white mouse', end=' ')
else:
print('brown cow', end=' ')
if 'y' not in mystr:
print('sat', end=' ')
else:
print('dropped', end=' ')
else:
print(mystr[4:26], end=' ')
print('down')
Signup and view all the answers
What will be the output of the following code?
mystr = "Howdy!Welcome to Texas A&M Engineering!"
print(mystr[:5] + mystr + mystr[-22:-1] + ' students!')
What will be the output of the following code?
mystr = "Howdy!Welcome to Texas A&M Engineering!"
print(mystr[:5] + mystr + mystr[-22:-1] + ' students!')
Signup and view all the answers
What will be the output of the following code?
x = 4
y = "Gig'em Aggies!"
while x < 100:
print(x, y)
x *= x - 2
y += y
What will be the output of the following code?
x = 4
y = "Gig'em Aggies!"
while x < 100:
print(x, y)
x *= x - 2
y += y
Signup and view all the answers
What will be the output of the following code?
x = 5
sum = 0
for i in range(4):
x *= i
sum += x
print(x, sum)
What will be the output of the following code?
x = 5
sum = 0
for i in range(4):
x *= i
sum += x
print(x, sum)
Signup and view all the answers
What will be the output of the following code?
AB = 0
V = [9, 5, -3, 6, -1, 0]
for i in range(len(V) - 2):
if V[i] < 0:
AB += 1
print("AB =", AB)
What will be the output of the following code?
AB = 0
V = [9, 5, -3, 6, -1, 0]
for i in range(len(V) - 2):
if V[i] < 0:
AB += 1
print("AB =", AB)
Signup and view all the answers
What will be the output of the following code?
x = 4
y = 8
t = x
x = y
y = t
z = x / y
print(z)
What will be the output of the following code?
x = 4
y = 8
t = x
x = y
y = t
z = x / y
print(z)
Signup and view all the answers
What will be the output of the following code?
x = 5 % 2 == 1 and 5 < 2 + 4
print(x)
What will be the output of the following code?
x = 5 % 2 == 1 and 5 < 2 + 4
print(x)
Signup and view all the answers
What will be the output of the following code?
a = 1
b = 2
c = "a"
d = int(float("3.14"))
if a == 1 and d == 3.14:
print("Green")
elif c == a or d > 3:
print("Red")
else:
print("Yellow")
What will be the output of the following code?
a = 1
b = 2
c = "a"
d = int(float("3.14"))
if a == 1 and d == 3.14:
print("Green")
elif c == a or d > 3:
print("Red")
else:
print("Yellow")
Signup and view all the answers
What will be the output of the following code?
x = 10
y = 5
if x % 2 == 0:
if y > 5:
print("A")
else:
print("B")
print("C")
else:
if y < 5:
print("D")
else:
print("E")
print("F")
print("G")
What will be the output of the following code?
x = 10
y = 5
if x % 2 == 0:
if y > 5:
print("A")
else:
print("B")
print("C")
else:
if y < 5:
print("D")
else:
print("E")
print("F")
print("G")
Signup and view all the answers
What will be the output of the following code?
x = 2
y = "A"
while x < 100:
print(x, y)
x *= x
y += y
What will be the output of the following code?
x = 2
y = "A"
while x < 100:
print(x, y)
x *= x
y += y
Signup and view all the answers
What will be the output of the following code?
for i in range(12):
if i % 2 != 1 and i % 3 == 0:
print(i)
What will be the output of the following code?
for i in range(12):
if i % 2 != 1 and i % 3 == 0:
print(i)
Signup and view all the answers
What will be the output of the following code?
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
print(data)
What will be the output of the following code?
data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
print(data)
Signup and view all the answers
Which code snippet below correctly finds the number of digits of the sum of two integers?
Which code snippet below correctly finds the number of digits of the sum of two integers?
Signup and view all the answers
Study Notes
Exam 1 Practice Problems
- Students are strongly advised to attempt practice problems in pencil and paper before verifying in an IDE.
- Partial credit is applicable to code writing problems, while multiple choice, fill in the blank, true/false questions are autograded.
- Calculators are prohibited during the exam.
- Students are also prohibited from using phones, the web, laptops, notes, or electronic media during the exam.
Autograded Style Problems:
-
Problem 1:
- Code outputs: "The answer is... B True 125"
-
Problem 2:
- Code outputs: "10 AA"
-
Problem 3:
- Code outputs: "False True"
-
Problem 4:
- Code outputs: "Hullabaloo Gig 'em Good Bull Aggies Whoop Howdy"
-
Problem 5:
- Code outputs: "[9, 16, 25]"
-
Problem 6:
- Code outputs: "1.0"
-
Problem 7:
- Code outputs: "The quick brown fox jumped down"
-
Problem 8:
- Code outputs: "Howdy!Howdy!Welcome to Texas A&M Engineering!Engineering students!"
-
Problem 9:
- Code outputs:
- "4 Gig'em Aggies!"
- "14 Gig'em Aggies!Gig'em Aggies!"
- Code halts after these two lines due to x becoming a large negative value
- Code outputs:
-
Problem 10:
- Code outputs: "0 0"
-
Problem 11:
- Code outputs: "AB= 2"
-
Problem 12:
- Code outputs: "2.0"
-
Problem 13:
- Code outputs: "True"
-
Problem 14:
- Code outputs: "Green"
-
Problem 15:
- Code outputs: "B, C, G"
-
Problem 16:
- Code outputs:
- "2 A"
- "4 AA"
- Code halts after these two lines due to x becoming a large value.
- Code outputs:
-
Problem 17:
- Code outputs:
- "0"
- "6"
- Code outputs:
-
Problem 18:
- Code outputs: "[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]"
-
Problem 19:
- The code snippet does not include finding the number of digits in the sum of two integers.
Problem 19 - Explanation:
- The code snippet given in
Problem 19
lacks the part to determine the number of digits in the sum, suggesting a missing part. -
To find the number of digits in the sum:
- Convert the sum to a string.
- Find the length of the string.
-
Example Implementation (assuming
numSum
has been calculated):-
digitCount = len(str(abs(numSum)))
-
print(digitCount)
- This code snippet first gets the absolute value of
numSum
to avoid counting the negative sign before converting it to a string. Then it calculates the length of the string, effectively counting the number of digits.
-
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Prepare for your upcoming exam with these practice problems focusing on autograded styles such as multiple choice, fill in the blanks, and logic-based outputs. Remember to practice using pencil and paper, as calculators and other electronic devices are prohibited during the exam. Test your knowledge and maximize your partial credit opportunities!