Exam 1 Practice Problems
19 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

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)

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)

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)

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=' ')

<p>Howdy Aggies Hullabaloo Whoop Good Bull</p> 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:])

<p>[1, 4, 9]</p> Signup and view all the answers

What will be the output of the following code?

x = 5 / 5
print(x)

<p>1.0</p> 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')

<p>The brown cow down</p> 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!')

<p>Howdy!Welcome to Texas A&amp;M Engineering!Texas A&amp;M Engineering students!</p> 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

<p>4 Gig'em Aggies! 8 Gig'em Aggies! 16 Gig'em Aggies!</p> 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)

<p>0 0</p> 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)

<p>AB = 0</p> 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)

<p>0.5</p> 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)

<p>True</p> 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")

<p>Red</p> 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")

<p>B C G</p> 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

<p>2 A 4 AA 16 AAAA</p> 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)

<p>0 6</p> 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)

<p>[[[1, 2], [3, 4]], [[5, 6], [7, 8]]]</p> Signup and view all the answers

Which code snippet below correctly finds the number of digits of the sum of two integers?

<p>numSum = num1 + num2 print(len(str(numSum)))</p> 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
  • 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.
  • Problem 17:
    • Code outputs:
      • "0"
      • "6"
  • 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.

Quiz Team

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!

More Like This

Use Quizgecko on...
Browser
Browser