Computer Science - Final

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Which function would you use to get the number of elements in a dictionary?

len

Assume a and b are variables that hold the base and height of a right triangle. The length of the long side (hypotenuse) is calculated as the square root of a^2 + b^2. Which expression calculates the length of the hypotenuse?

math.sqrt(math.pow(a,2)) + math.pow(b,2)))

Choose the option that gives 'Great' as the output.

my_list = ['books', 'are', 'greate', 'for', 'learning'] my_list.sort() print(my_list.pop(3))

Given a list my_list = [[0, 1, 2], [3, 4, 5], [6, 7, 8]] how would you access the value 7?

my_list [2] [1]

Choose the correct statements to complete the code below My_list = [3,2,5] ### fill the code here ### print (my_list)

my_list.extend([1, 4]) my_list.sort()

What condition should be used replace cond to ouptut 'Same name' only if the values of two variables are the same? my_name = input('Enter my name: ') your_name = input('Enter your name: ') if cond: print('Same name")

my_name == your_name

Consider the list my_list = ["www", 'python', 'org'] Choose the option that assigns to my_string the value www.python.org

my_string = ('.').join(my_list)

Which expression replaces cond to make the loop ask for names until 'quit' is entered? name = input('What is your name 9'Quit' to exit)?') while cond: print ('Hello, ', name) name = input('What is your name('quit' to exit)?')

name != 'quit'

What will be assigned to s_string after the execution of the following code? special = '1357 Country Ln.' s_string = special [ :4]

'1357'

What is the value of new_title? title = 'Python for Beginners" tokens = title.split( ' ') if 'Chapter 1' not in tokens: tokens.append('Chapter 1') new_title = '_'.join(tokens)

'Python_for_Beginners_Chapter 1'

Which expression is equivalent to: not x and y == a and b?

((not x) and (y == a)) and b

Which operator is evaluated first: x + y < y - z * 2?

*

What is the first negative index in a string

-1

Which input value causes 'Goodbye' to be output next? x = int(input()) while x > 0: # Do something x = int(input()) print('Goodbye')

-5

What are the valid indexes for the string 'New York'?

0 through 7

What is the value of x after the following code is executed? x = 17 if x * 2 <= 34: x = 0 else: x = x + 1 x = x + 1

1

What is the ending value of z? x = 0.6 z = math.pow(math.ceil(x),2)

1.0

Select the output generated by the following code: new_list = [10, 10, 20, 30, 40, 40] for i in range (3): print( new_list[i]) new_value = new_list.pop(0)

10 20 40

What is the value of test_val after the following code is executed? a = 12 test_val = 6 if a * 2 == test_val: a = a + 7 else: test_val = 2 * a test_ val = a + 1

13

What is x's final value? x = 10 y = 20 if y<= 2 * x: x = x + 5 else: x = x * 2

15

What is output? x = 18 while x % 3 == 0: print (x , end = ' ') c = x // 3

18 6

What is the value of: 1 + int(3.5) / 2?

2.5

What is displayed when the following code is executed? day = 23 if day % 10 == 1: ending = 'st' elif day % 10 == 2: ending 'nd' elif day % 10 == 3: ending 'rd' else: ending = 'th' print(str(day) + ending)

23 rd

What is ending value of count? my_list = [3, -4, 0, -1, 2, 1] n = 0 count = 0 while n < len(my_list): if my_list[n] > 0: count = count + 1 n = n + 1

3

What is the output? my_list = [3, 7, 0, 2, -1, 8] index = 0 while my_list[index] > 0: print( my_list [index], end = ' ') index += 1

3 7

How many iterations will the code below execute? count = 7 while count > 0: count -= 2 print(count)

4

What is the result of the code: y = 2**2 + 6 / 2 -3

4

What initial value of x will cause an infinite loop? x = int(input()) while x != 0: x = x - 2 print(x)

9

What is the value of x after the following code is executed? x = 7 if x > 7: x = x + 1 x = x + 2

9

What formatting presentation type is used to display an integer? i.e '{}'.format()

:d

What are two parts of an if statement?

A condition and a body

Which input for variable c causes 'Done' tp be output next? c = 'y' while c == 'y': #Do something print(' Enter y to continue, n to quit: ', end = ' ') c = input() print('Done')

Any value other than 'y'

What is the number of the first index in a list dictionary?

Dictionary is not indexed by number

With the algorithm shown below, what will be the output when grade is assigned with the value 75?

Else of grade < 85 Print 'B' to output

What is the output? my_string = 'greetings!' print(my_string == 'greetings!') print('tin ' in my_string) print('hello' > my_string)

False True false

Given x = 1, y = 2, and z = 3, how is the expression evaluated? In the choices, items in parentheses are evaluated first. (x == 5) or ( y == 2) and ( z == 5)

False OR (Ture AND False) ---> False OR False --> False

Which is true of the badly formatted code? x = input() if x == 'a' print('first') print('second')

The first print() statement must be indented

What is the output? new_list = ['Python', 'development'] new_list.append(in progress') print(new_list)

['python', 'development', 'in progress']

Which list will be referenced by the variable number after the execution of the following code? number = range (0, 9, 2)

[0, 2, 4, 6, 8]

Complete the following code to print the average of the list. new_list = [0, 1, 2, 3, 4] ****the solution **** print( 'The average is {}'.format(avg))

avg = sum (new_list)/len(new_list)

To store a condition that can be true or false, you use a ______ variable

boolean

What conditions have to be true to make the following code display 'B"? if color == 'red': if style < 3: print('A') elif style < 5: print('B') else: print('C') elif color == 'blue': print('D')

color is 'red; and style if 4

What would you use if an element is to be removed from a specific index?

del statement

A loop where you do not know how many iterations it takes to accumulate a target balance is called ______

event controlled

If you need to check each character in a string, the ____ loop makes this process easy to program.

for

Consider the following while loop: j = 10 while j >= 5: print('X') J = J - 1 Which of the following for loops will generate the same output?

for j in range(10, -1, -2): print ('X')

What is the output? new_string = 'One giant leap for mankind' print(new_string [4:12])

giant le

What is the output? my_list = ['hello', 'good' , 'morning'] print(my_list[1] [:3])

goo

If the start index is ________ the end index, the slicing expression will return an empty string.

greater than

What is the expression that will cause the loop to display all odd numbers from 1 to 100. i = 1 while i <= 100: print (i) i = **** your solution*****

i + 2

The following program prints the number of integers in my_list that are greater than the previous integer in the list. Which choice fills in the blank to complete the for loop? my_list = [3, 2, 7, 8, 6, 9] count = 0 for ______: if my_list [i] > my_list [i-1]: count = count + 1 print( count)

i in range(1, len(my_list))

Which branch structure is necessary if a program needs to output "yes" if a variable's value is positive, or 'No' other wise?

if - else

A child is required to use a booster seat in a car until the clid is 9 years old, unless the child reaches the height of 59 inches before age 9. Which expression can be used to decide if a child requires a car seat? The expression should return True if the child requires a car seat?

if age >= 9 or height >= 59:

A company wants to send a reminder email to users who have not logged in for more than 10 days, but less than 20 days> Which expression can be used decided if a user should get an email or not?

if days_since_login > 10 and days_since_login < 20:

Which has an error? Assume x = 10 and y = 20.

if x = y:

In a dictionary, you use a ____ to locate a specific value.

key

Which expression can be used to decide if x is not between 10 and 20?

not ( 10 < x < 20)

Which print statement displays: 'Tokyo had 9.273000 million people in 2015'?

print('{:s} had {:f} million people in {:d}'.format('Tokyo', 9.273, 2015))

Consider the list my_list = [1880, '990EZ', 'Tax Forms'] Which statement gives 990EZ as the output?

print(my_list[1])

Which choice fills in the blank so that the output prints one line for each item in sports_list? sports_list = [ 'Hockey', 'Football', 'Cricket' ] for i in _______: print ( '{:d}. {:s}'.format(i+1, sports_list[i]))

range(len(sports_list))

In python the comparison > is called _____ operator

relational

What is the expression that will cause the output to be a count of how many negative values are in temperatures? temperatures = [-2, 8, 4, -7, 18, 3, -1] count = 0 for t in temperatures: if *** your solution ***: count = count + 1 print( 'Total negative temperatures:", count)

t < 0

Which of following method will change the string Python Programming into PYTHON PROGRAMMING?

upper()

What is the format for the while loop header in Python?

while condition:

What is the difference between while and if?

while executes as long as the condition is true instead of if the condition is true

What string method is used to test if an input value x is a number?

x.isdigit()

If x = 10 and y = 20, which expression is True?

y >= x

What is the correct structure for creating a dictionary of month names to be accessed by months numbers?

{1: 'January', 2: 'February', 3: 'March'}

What is the output when the following code is executed? score = 65 group = '' if score <= 60: group = group + 'A' if score <- 70: group = group + 'B' if score <= 80: group = group 'C' else: group = group + 'D' print(group)

BC


Kaugnay na mga set ng pag-aaral

Chapter 1 - The Comparative Approach

View Set

English 11B - Unit 6: Final Exam

View Set

Meninges of the Brain, Frontal Section

View Set

ASREB - A4 - Liens & Encumbrances

View Set

FBLA Sports management and Marketing

View Set