Podcast
Questions and Answers
What is 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 is 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 131
What is the output of the following code? n = 1; p = 'A'; while n < 10: p += p; n += 3; print(n, p)
What is the output of the following code? n = 1; p = 'A'; while n < 10: p += p; n += 3; print(n, p)
10 AAAAAAAA
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 is 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 is 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 is the output of the following code? x = 5 / 5; print(x)
What is 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': ...
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': ...
Signup and view all the answers
What is the output of this code? mystr = "Howdy!Welcome to Texas A&M Engineering!"; print(mystr[:5] + mystr + mystr[-22:-1] + ' students!')
What is the output of this code? mystr = "Howdy!Welcome to Texas A&M Engineering!"; print(mystr[:5] + mystr + mystr[-22:-1] + ' students!')
Signup and view all the answers
What is the output of the following code? x = 4; y = "Gig'em Aggies!"; while x < 100: print(x, y); x *= x - 2; y += y
What is 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 this code? x = 5; sum = 0; for i in range(4): x *= i; sum += x; print(x, sum)
What will be the output of this 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 result of executing this 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 result of executing this 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 would be the output of this code? x = 4; y = 8; t = x; x = y; y = t; z = x / y; print(z)
What would be the output of this code? x = 4; y = 8; t = x; x = y; y = t; z = x / y; print(z)
Signup and view all the answers
What is the output of this code? x = 5 % 2 == 1 and 5 < 2 + 4; print(x)
What is the output of this code? x = 5 % 2 == 1 and 5 < 2 + 4; print(x)
Signup and view all the answers
What will be printed by this 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 printed by this 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 is the expected output? 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 is the expected output? 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 is the result of running this code? x = 2; y = "A"; while x < 100: print(x, y); x *= x; y += y
What is the result of running this code? x = 2; y = "A"; while x < 100: print(x, y); x *= x; y += y
Signup and view all the answers
What will be printed by this code? for i in range(12): if i % 2 != 1 and i % 3 == 0: print(i)
What will be printed by this code? for i in range(12): if i % 2 != 1 and i % 3 == 0: print(i)
Signup and view all the answers
What is the output of the following code? data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]; print(data)
What is the output of the following code? data = [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]; print(data)
Signup and view all the answers
The variable 'numSum' is defined as the sum of two integers, num1 and num2. The number of digits in numSum can be found by which code snippet? num1 = int(input("Enter first integer: ")
.
The variable 'numSum' is defined as the sum of two integers, num1 and num2. The number of digits in numSum can be found by which code snippet? num1 = int(input("Enter first integer: ")
.
Signup and view all the answers
Study Notes
Exam 1 Practice Problems
- Students are advised to practice the problems using pen and paper, not an IDE.
- Code solutions should be commented, and algorithms should be outlined before writing code.
- Quizzes should be reviewed for additional autograded style problems, including fill in the blank, multiple choice, multiple answer, and true/false questions.
- Partial credit will be available for code writing problems, but not for autograded problems.
- Students may not use calculators, phones, the internet, laptops, books, notes, lectures on Canvas, or any other form of electronic media during the exam.
- The following problems should be attempted using pencil and paper, and solutions should be checked in an IDE afterwards.
Problem 1
- The output:
The answer is... A True 114
- The
if-elif-else
statement checks the values ofa
andb
and prints accordingly. - The variable
z
is assigned the result ofc and bool(a)
, which evaluates toTrue
and is printed. - The variable
d
calculates the result ofa ** 3 + 25 % 3 - 12 // 5
and prints the result, which is114
.
Problem 2
- The output:
10 AAA
- The
while
loop iterates untiln
is less than 10. - Each iteration, the variable
p
is doubled andn
is increased by 3. - The final values of
n
andp
are printed.
Problem 3
- The output:
False True
- The variable
a
is assignedTrue
, andb
is assignedTrue
becausebool('False')
evaluates toTrue
. - The variable
c
is assignedFalse
as5 > 8
is false. - The variable
d
is assignedFalse
because theand
operator requires all conditions to be true. - The variable
e
is assignedTrue
because theor
operator evaluates toTrue
if at least one condition isTrue
.
Problem 4
- The output:
Howdy Gig 'em Aggies Whoop Hullabaloo Good Bull
- The
for
loop iterates through the elements of themynums
list. - For each element, the code prints the corresponding string element from the
mystrs
list.
Problem 5
- The output:
[9, 16, 25]
- The
for
loop iterates 5 times, appending the square ofi
tomylist
. - The function
mylist[-3:]
returns the last 3 elements ofmylist
.
Problem 6
- The output:
1.0
- The variable
x
is assigned the result of5/5
, which is1.0
. - The code prints the value of
x
.
Problem 7
- The output:
The fox brown cow sat down
- The
if-elif-else
statement checks conditions based on the content ofmystr
. - The
if
branch executes if the stringmystr
is equal to "q", and printsfox
andjumped
. - The
elif
branch executes if the stringmystr
contains “x”, and printsbrown cow
andsat
. - The
else
branch executes if the previous conditions areFalse
, and printsquick brown fox jumped over the lazy
.
Problem 8
- The output:
Howdy!Howdy!Welcome to Texas A&M Engineering! Engineering! students!
- The code concatenates multiple substrings of
mystr
and prints the result.
Problem 9
- The output:
4 Gig'em Aggies! 4 Gig'em Aggies!Gig'em Aggies!
- The
while
loop iterates untilx
is less than 100. - Each iteration, the code prints
x
andy
, then multipliesx
by itself minus 2, and concatenatesy
with itself. - The loop terminates after two iterations because the value of
x
becomes less than 100.
Problem 10
- The output:
0 0
- The
for
loop iterates 4 times. - Each iteration, the code multiplies
x
byi
, and adds the result tosum
. - The code prints the final value of
x
andsum
.
Problem 11
- The output:
AB = 2
- The
for
loop iterates through the elements ofV
list, excluding the last two. - It counts the number of negative elements and updates
AB
accordingly. - The final value of
AB
is printed.
Problem 12
- The output:
2.0
- The code swaps the values of
x
andy
using a temporary variablet
. - It then calculates
z
by dividingx
byy
and prints the result.
Problem 13
- The output:
True
- The code evaluates the expression
5 % 2 == 1 and 5 < 2 + 4
which isTrue and True
, ultimately evaluating toTrue
.
Problem 14
- The output:
Green
- The
if
statement checks ifa
is equal to 1 andd
is equal to 3.14, prints "Green" because both are true.
Problem 15
- The output:
B C G
- The
if-else
statement checks the values ofx
andy
and prints the corresponding result.
Problem 16
- The output:
2 A 4 AA
- The
while
loop iterates untilx
is less than 100. - Each iteration the code prints
x
andy
, then squaresx
and concatenatesy
with itself. - The loop terminates after two iterations because the value of
x
becomes greater than 100.
Problem 17
- The output:
0 6 12
- The
for
loop iterates from 0 to 11. - The
if
statement checks ifi
is not divisible by 2 and divisible by 3. - If true, the corresponding
i
value is printed.
Problem 18
- The output:
[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
- The code prints the nested list
data
, showing the structure of nested lists.
Problem 19
- The code snippet to find the number of digits of the sum of two integers:
myStr = str(numSum) print(len(myStr))
- The code converts the
numSum
integer to a string (myStr
). - It then uses the
len
function to determine the length of the string, which represents the number of digits. - The
len
function tells us the length of the string, which corresponds to the number of digits in the sum.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Related Documents
Description
Prepare for your Exam 1 with these practice problems focusing on algorithms and code writing. Students should solve the problems on pen and paper and review their solutions in an IDE. Ensure thorough understanding of conditional statements and boolean logic.