Algorithms
Arithmetic and Strings
Decisions, Booleans
Loops
100

The Python interpreter reads and executes your program________________   instruction(s) at a time.

One

100

What is the output for the following code when the user enters 5 at the first prompt and 10 and the second prompt? 

a = input(“Enter the value of a:”)

b = input(“Enter the value of b:”)

print(a + b)

510

100

What is the output of the following code if executed?

attendance : bool = True

a : int = 5

words : str = “!”

if attendance:

    words = “here” + words

elif not attendance or a > 3:

    words = “away”

if -2 < a < -3 ** 2:

    words = “I am not” + words

else:

    words = “I am” + words

print(words)

I amhere!

100

whats the output of the following code?

x = 6

while x >= 0:

    if x % 2 == 1:

        print("ODD")

    else:

        print("EVEN")

    x = x - 3

EVEN

ODD

EVEN

200

Formally, an algorithm describes a sequence of steps that is:

1)     

2)     

3)     

Executable

Terminating

Unambiguous

200

What is num3’s type?

num1 : int = 20

num2 : int = 10

num3 : ____ = num1 + num2 / 2

Float

200

a : str = “COMP 1001”

b : str = “CS”

c : int = 10

if c in a:

    if a[0] == b[0]:

        print(“Hello”)

    if c > int(a[7:]):        

        print(“World”) 

    else:
        print(“Everyone”)

else:

    print(“<(^-^)>”)

Hello

World

200

What is the output of this code?

x : int = 0

while not (x >= 0):

    print("x", end = "")

    x += 1

print("!")

!

300

Which Pokemon do Steph and Cindy have
after the code below is executed?

stephs_pokemon : str = “Bulbasaur”

cindys_pokemon : str = “Pikachu”

stephs_pokemon = cindys_pokemon

cindys_pokemon = stephs_pokemon

Pikachu

Pikachu

300

What is printed after the following code segment?

words = "CS" + "1001" * len("hi!"[2])

print(words)

CS1001

300

What is the syntax error in the code bellow

attendance: bool = True

words: str = ""

if attendance == True:

    words = "Awesome!"

if not attendance and attendance:

    words = "Attend Class!"

else (attendance or (attendance and False)):

    words = "Oh my!"

There should be no condition for else

300

What is the output of the follwing code?

x = 0

for i in range(3):

    while x < i:

        print("#", end="")

        x += 1

    print()

[blank line]

#

#

400

What kind of error is present in the code below?

print("Hello", end = " ")

print("World', end = '!\n')

Second line the ' should be "

400

Fill-in-the-blank for the formatting to satisfy all of the following:

1) has a width of 5, 

2) value is left-aligned, and

3) it prints exactly two decimal places.

*Note: value is a float

print(“result:_______” %value)

print("result:%-5.2f" % value)

400

What is printed after the following code executes, and why?

from math import sqrt

NUMB : float = 2.0
sqrt_NUMB : float = sqrt(NUMB)

if sqrt_NUMB ** 2 == NUMB:
    print(“Obviously this.”)

else:
    print(“HOW?!”)

HOW?!

Because sqrt(2) is a irrational number(with no end in their floating digits) and in computer we can save an estimation of it

400

How many times is  c  printed after the given code executes?

for i in range(10):

    x = i

    while x > 0:

        print("c", end="")

        x = x - 3

    print()

18

500
Flowchart problem
Flowchart Answer
500

What is printed after the code below executes?

num1 : int = 20

num2 : int = 10
string1 : str = “hello”

num3 : int = num1 + num2 / 2
num4 : int = num3 + 10 % len(string1[1:5:2])

print(num4)

25.0

500

Below is incorrect code for maximum value of integers a, b, c.
Give a counterexample to show the code is incorrect.
In other words…give specific values for a, b, and c that give the wrong answer.

max_value : int = a

if b > a and b > c: 

   max_value = b

elif c > a and c > b:

   max_value = c

a = 4

b = 5

c = 5

500

What is printed after the given code executes?

for i in range(-1, 2):

    x = -2

    while x < i:

        if x % 2 == i % 2:

            print("x", end="")

        else:

            print("o", end="")

        x += 1

    print()

o

xo

oxo


M
e
n
u