Engineering Exam Rat Problems

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

The following code changes the list grades. grades = [87, 93, 75, 100, 82, 91, 85] sublist = grades[1:4] sublist = [] True or False

False

The following code outputs 0.3 x = 0.1 + 0.1 + 0.1 print(x) True or False

False

The following code outputs 10 x = "102" - "2" print(x) True or False

False

The following code outputs an error message in the Console window. x = "10" + "2" print(x) True or False

False

The following code outputs an error message. x = "102"*2 print(x) True or False

False

The following code will print three values for z. z = 3 z = 5 z = 1 print(z) True or False

False

The following variable name is valid: 3rdName True or False

False

The following variable name is valid: Howdy-World True or False

False

The individual elements of a list are numbered (indexed), starting at 1. True or False

False

The line of code z = z + 1 represents a mathematical equation. True or False

False

Trying to create a list with the following statement will result in an error. a_list = [ [1, 0, 2], [ ], 24.5 ] True of False

False

When building software, we should use an "arch" process because we will always have a "stable" piece of software, even when not complete. True or False

False

When creating a comment, it is a good practice to use a triple-quoted string. True or False

False

When we want to repeat indefinitely, we should use a for loop. True or False

False

You should use comments to restate what should be obvious from reading the code. True or False

False

a = 0 b = 4 while a == 0: a = 1 b += a a = 0 print(b) The code outputs 5 True or False

False

age = input("What is your age (whole years)? ") If the user enters 18 in the Console window then the type of the variable age is Integer. True or False

False

bool('0') - has the value False True or False

False

float(True) has the value 0.0 True or False

False

for my_var in range(0,8,2): print(my_var) The loop iterator my_var takes on values 0, 2, 4, 6, 8. True or False

False

for my_var in range(1,5,1): print(my_var) The loop iterator my_var takes on values 1, 2, 3, 4, 5. True or False

False

grades = [75, 100, 85] for grade in grades: grade = 0 The code above changes the value of each element in the list grades to zero. True or False

False

grades = [87, 75, 85] grades.append(10) print(grades) The code above will output: [97, 85, 95] True or False

False

grades = [87, 93, 75] print(grades) The code above will output 87 93 75 True or False

False

list1 = [1, 2, 3] list2 = [4, 5, 6] list3 = list1 + list2 print(list3) The code above will output: [5, 7, 9] True or False

False

my_list = [1, 2, 3, 4] print(my_list[4]) The code above will output: 4 True or False

False

my_var = 12 a_list = ['Howdy!', 102, True, my_var*3] print(a_list) The code above creates an error and will not print the list values. True or False

False

while False: print("Here we go again.") This is an infinite loop. True or False

False

x = "True" The type of the variable x is Boolean. True or False

False

x = 5 / 5 The type of the variable x is Integer. True or False

False

x = int(float('34.56')) This is an error. True or false

False

x = str(1/4) The variable x has the value '1/4' True or False

False

What is printed to the console during execution of this code snippet? # how_many = 3 if how_many == 2: print('Couple') elif how_many < 5: print('Few') elif how_many < 10: print('Several') else: print('None') #

Few

A or B The or operator returns True if either A or B are True (or when they are both True). True or False

True

A relational operator is basically a comparison between two quantities. True or False

True

A variable (a box of memory) can hold some unit of information e.g. a number, like the number 102. True or False

True

Booleans are pretty simple - they are variables that have just two possible values: True or False. True or False

True

By default, the print command (when printing) ends the line after printing (so next thing appears on next line). True or False

True

By default, the print command (when printing) separates all the items (listed separated by commas) with a space. True or False

True

Code blocks and indentation. Good practice is to use the standard recommended 4 columns (that is, spaces) per indentation level. True or False

True

Code blocks and indentation. Unlike most other programming languages, the indentation is required in Python. True or False

True

Comments are descriptive text placed into the code of the program. True or False

True

Comments are meant to help people understand the purpose of the code. True or False

True

Computers have memory - the ability to remember information. True or False

True

Conditionals. If we have exactly two possible cases, and we know what we want to do in both the True case and the False case, we can use the if-else structure. True or False

True

Conditions are assessed as Boolean variables and expressions. True or False

True

Consider the following for loop structure: for i in range(10): print("Doing Something") We call i an "iterator" (or loop variable). True or False

True

Debugging means: find where the program is failing, determine the error, and fix it. True or False

True

Floating-point numbers can represent numbers with a decimal point. True or False

True

For strings, the + operator means "concatenation". True or False

True

Given num_people = 10, num_cars = 2, user_key = 'q', evaluate the following expression (True or False) not (user_key == 'x') or ((num_people > 5) and (num_cars >= 1)) True or False

True

GradeList[2] The expression above means: The list name is GradeList and we want element at index 2 (the third element). True or False

True

Ideally, we should write the tests before we write our program. Realistically, people often write tests after writing (at least some) code and don't write sufficiently thorough tests. True or False

True

If we comment the second line of code in the Example "guessing game" then the interpreter will generate a NameError when it tries to evaluate the condition in the while statement. True or False

True

In Python, the name of a variable can start with a letter (lowercase or uppercase) or an underscore (_). But, you generally shouldn't start them with an _ since this tends to imply certain things about the variable. True or False

True

In Python, we can use lists to group several data values together in one container. We assign a single name to the entire list as a whole. True or False

True

In the command print(x) x can be an expression. True or False

True

Integers can be positive or negative or zero. True or False

True

It can be helpful to think of floating-point numbers as numbers in scientific notation. There's a Mantissa (the values, assumed to have 1 digit before the decimal point) and, there's an Exponent (the power of 10 that the Mantissa is multiplied by). So, something like 1.234567 times 10 to the third is the number 1234.567. True or False

True

It is (sometimes) possible to convert a value of one type into a value of another type. True or False

True

Lists are denoted by square brackets, with comma-separated values inside. True or False

True

One execution of the indented code (loop body) is sometimes called an iteration of the loop. True or False

True

One subfield of computer science called "software engineering" deals with the processes for constructing large pieces of software. True or False

True

One way of creating a list is by surrounding a sequence of values with brackets [ ]. True or False

True

Order of operations: the expression x == 5 or y == 10 and z != 10 is evaluated as (x == 5) or ((y == 10) and (z != 10)) True or False

True

Python assignment statements have the form: <Variable name> = <Value to assign> True or False: When this statement is executed: We FIRST evaluate the right hand side Then, we assign that value to the left hand side

True

Python provides many built-in data types . The Lecture 3 handout (videos) introduces the following data types: Integers, Floating-Point numbers, Booleans, and Strings. True or False

True

Slicing does not give out-of-range errors. If you try to go past the beginning/end of a list when slicing, you just get the beginning/end of the list. True or False

True

Software bugs and errors are VERY common, and we should never assume that even a small amount of code is working without testing. True or False

True

Sometimes we may have a situation where there are more than two possible outcomes. In this case, we can make use of the if-elif-else structure. True or False

True

Strings are used to describe text. Strings are made up of characters "strung" together. True or False

True

The "break" statement is a keyword that you can put in the middle of your loop. It immediately stops that loop. True or False

True

The "continue" statement is a keyword that you can put in the middle of your loop. It immediately stops that iteration in the loop. True or False

True

The "while" will repeat the set of instructions until the condition is false. True or False

True

The following code inserts the value 99 to the list grades. grades = [87, 93, 75, 100] grades[2:2] = [99] True or False

True

The following code outputs 3.0 x = 1.0 + 2 print(x) True or False

True

The following code removes three elements from the list grades. grades = [87, 93, 75, 100, 82, 91, 85] grades[1:4] = [] True or False

True

The following expression can be used to test if a variable is between 0 and 100, inclusive (variable1 >= 0) and (variable1 <= 100) True or False

True

The following expression can be used to test if two variables are equal and negative (variable1 == variable2) and (variable1 < 0) True or False

True

The following two loops are equivalent to each other. Loop 1: for i in range(10): print("Doing Something") Loop 2: i = 0 while i < 10: print("Doing something") i += 1 True or False

True

The indentation should be consistent through the program, and must be the same for every line in the conditional "block" True or False

True

The not operator returns the opposite of what it is given - True for False and False for true. True or False

True

The range type represents an immutable sequence of numbers and is commonly used for looping a specific number of times in for loops. True or False

True

The result of a relational operator is a Boolean value. True or False

True

The way repetition is handled in programs is through a structure called a "loop." There are a few different forms that loops can take, but the key to all of them is that the loop will repeat a set of instructions (body of the loop) several times. True or False

True

There are many approaches to program design, but all of them involve stopping to think about design before trying to implement. True or False

True

To change the value of an element in the list, we must access the element directly using the bracket [] syntax. True or False

True

To create a comment in Python, you can place a # in front of a line of text. True or False

True

To create branches in programs, we describe the conditions for each branch. True or False

True

WE can make lists of lists (nested lists). True or False

True

We can convert strings to lists using the list() and split() commands. True or False

True

We can modify the "guessing game" program to count and print the number of guesses it took the user to guess the secret number. True or False

True

We can nest condition statements True or False

True

We can nest one loop inside another. True or False

True

We can say that programming is our attempt to translate human procedural knowledge into a set of instructions that a computer can understand. True or False

True

We can slice strings just like we slice lists, but we cannot modify characters in strings because strings are immutable. True or False

True

We can think of main memory as being a bunch of "boxes" that hold information. A variable name acts like a label on the box. True or False

True

We can use a for loop when we want to iterate through a specific, known set of items. True or False

True

We can use the input command to get input in the Console window. For example, we can ask the user to input her/his name: name = input("What is your name? ") True or False

True

When building software, the "pyramid" style lets you develop code incrementally. True or False

True

When we have a known number of iterations, we can use a for loop. True or False

True

When we have a large problem, try first breaking it down into the major steps involved - what is it we need to do? True or False

True

When we want to repeat until a general condition is met, we should use a while loop. True or False

True

When you are writing code, the idea is to write a small section of the code, and then TEST that code. True or False

True

Whitespace and comments can be used to provide visual breaks in code to help human beings read the code. True or False

True

Whitespace refers to blank lines and spaces in code. True or False

True

You should use comments to define the purpose of a particular variable. True or False

True

You should use comments to describe the purpose of a line or a section of code. True or False

True

bool('False') - has the value True True or False

True

bool(4.25) has the value True True or False

True

for my_var in 'abc': print(my_var) The loop iterator my_var takes on values 'a', 'b', 'c' True or False

True

grades = [87, 75, 100, 82, 91, 85] print(grades[4:5]) The code above will output: [91] True or False

True

grades = [87, 93, 75] j = 50 grades += [j*2] print(grades) The code above will output: [87, 93, 75, 100] True or False

True

int(True) has the value 1 True or False

True

my_string = "" # empty string bool(my_string) - has the value False True or False

True

my_string = 'ABC' for my_var in my_string: print(my_var) The loop iterator my_var takes on values 'A', 'B', 'C' True or False

True

not x == 5 evaluates as not (x == 5) True or False

True

x -= 5 means x = x - 5 True or False

True

x = """Hello!""" The type of the variable x is String. True or False

True

x = int('34.56') This is an error. True or False

True

x = int(-34.56) The variable x has the value -34 True or False

True

x = x + c can be written as x += c True or False

True

The following assignment statement is valid: x + y = z True or False

False

The element number (index) must be in integer literal (cannot be a variable or an expression). True or False

False

What are the values of n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs after the code executes? grades = [85,92,68,75,96,54,88,73,75,71] n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs = 0,0,0,0,0,0 for i in grades: if i >= 60: n_pass += 1 elif i >= 90: n_As += 1 elif i >=80: n_Bs += 1 elif i >= 70: n_Cs += 1 elif i >=60: n_Ds += 1 else: n_Fs += 1 print('pass = ',n_pass," A's = ", n_As, " B's = ", n_Bs, " C's = ", n_Cs, " D's =", n_Ds, " F's = ", n_Fs) What is the value of n_As?

0

What are the values of n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs after the code executes? grades = [85,92,68,75,96,54,88,73,75,71] n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs = 0,0,0,0,0,0 for i in grades: if i >= 60: n_pass += 1 elif i >= 90: n_As += 1 elif i >=80: n_Bs += 1 elif i >= 70: n_Cs += 1 elif i >=60: n_Ds += 1 else: n_Fs += 1 print('pass = ',n_pass," A's = ", n_As, " B's = ", n_Bs, " C's = ", n_Cs, " D's =", n_Ds, " F's = ", n_Fs) What is the value of n_Bs?

0

What are the values of n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs after the code executes? grades = [85,92,68,75,96,54,88,73,75,71] n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs = 0,0,0,0,0,0 for i in grades: if i >= 60: n_pass += 1 elif i >= 90: n_As += 1 elif i >=80: n_Bs += 1 elif i >= 70: n_Cs += 1 elif i >=60: n_Ds += 1 else: n_Fs += 1 print('pass = ',n_pass," A's = ", n_As, " B's = ", n_Bs, " C's = ", n_Cs, " D's =", n_Ds, " F's = ", n_Fs) What is the value of n_Cs?

0

What are the values of n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs after the code executes? grades = [85,92,68,75,96,54,88,73,75,71] n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs = 0,0,0,0,0,0 for i in grades: if i >= 60: n_pass += 1 elif i >= 90: n_As += 1 elif i >=80: n_Bs += 1 elif i >= 70: n_Cs += 1 elif i >=60: n_Ds += 1 else: n_Fs += 1 print('pass = ',n_pass," A's = ", n_As, " B's = ", n_Bs, " C's = ", n_Cs, " D's =", n_Ds, " F's = ", n_Fs) What is the value of n_Ds?

0

What are the values of n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs after the code executes? grades = [85,92,68,75,96,54,88,73,75,71] n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs = 0,0,0,0,0,0 for i in grades: if i >= 60: n_pass += 1 elif i >= 90: n_As += 1 elif i >=80: n_Bs += 1 elif i >= 70: n_Cs += 1 elif i >=60: n_Ds += 1 else: n_Fs += 1 print('pass = ',n_pass," A's = ", n_As, " B's = ", n_Bs, " C's = ", n_Cs, " D's =", n_Ds, " F's = ", n_Fs) What is the value of n_Fs?

1

What is the output of the following code? a=[[1,2,3],[4,5,6],[7,8,9]] for i in range(len(a)): for j in range(len(a)): if (a[i][j]%2 == 0 and a[i][j] > 6): a[i][j]=0 print(a[i][j], ' ',end='') print()

1 2 3 4 5 6 7 0 9

7 // 3 ?

2

What is the value of z after the following code executes: x = 2 y = 3 x = x * x y = y + 2 z = x * y z = z + 1 z = ?

21

What is the value of the variable counter after the following code is executed? user_age = 34 counter = 0 if user_age < 16: counter += 1 if user_age > 15: counter += 1 if user_age > 17: counter += 1 if user_age > 24: counter += 1 if user_age > 34: counter += 1

3

What will the following output? Type ERROR if you think that the code results in an error. grades = [7, 3, 5, 10, 2, 1, 8] grades[1] = 4 grades[2] -= 6 grades[3] = grades[1]+grades[2] print(grades[3])

3

What is the value of x after the following code executes: x = 2 y = 3 x = x * x y = y + 2 z = x * y z = z + 1 x = ?

4

What will the following output? grades = [87, 93, 75, 100] print(len(grades))

4

What is the value of y after the following code executes: x = 2 y = 3 x = x * x y = y + 2 z = x * y z = z + 1 y = ?

5

What are the values of n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs after the code executes? grades = [85,92,68,75,96,54,88,73,75,71] n_pass, n_As, n_Bs, n_Cs, n_Ds, n_Fs = 0,0,0,0,0,0 for i in grades: if i >= 60: n_pass += 1 elif i >= 90: n_As += 1 elif i >=80: n_Bs += 1 elif i >= 70: n_Cs += 1 elif i >=60: n_Ds += 1 else: n_Fs += 1 print('pass = ',n_pass," A's = ", n_As, " B's = ", n_Bs, " C's = ", n_Cs, " D's =", n_Ds, " F's = ", n_Fs) What is the value of n_pass?

9

Which code snippet below will correctly provide a count of the number of numbers between 1 and 100, inclusive that are evenly divisible by 5? # A count = 0 for i in range(1, 101): if i % 5 == 0: count = count + 1 print( count ) # # B count = 0 for i in range(0, 100): if i % 5 == 5: count = count + 1 print( count ) # # C count = 0 for i in range(0, 100): if i % 5 == 0: count = count + 1 print( count ) # # D None of these provides the required count. # # E count = 0 for i in range(0, 100): if i % 5 != 1: count = count + 1 print( count ) #

A

Which of the following code snippets will result in mySum equal to 15? # A mySum = 0 for i in range(6): mySum = mySum + i # # B mySum = 0 for i in range(5): mySum = mySum + i # # C mySum = 0 for i in range(1, 7): mySum = mySum + i # # D None of these. # # E mySum = 0 for i in range(1, 5): mySum = mySum + i #

A

What "sequence" of numbers is created by the following call to the range() function? range( 0, -11, -2) # A 1, -1, -3, -5, -7, -9, -11 # # B None of these correctly represent what will be printed. # # C 0, -1, -3, -5, -7, -9, -11 # # D 0, -11, -22 # # E 0, -2, -4, -6, -8, -10, -11 #

B

Which code snippet below returns True if the value of myVar lies between 0 and 100, inclusive? # A (myVar <= 0 or myVar >= 100) # # B (myVar < 0 and myVar > 100) # # C (myVar >= 0 and myVar <= 100) # # D None of these. # # E (myVar <= 0 and myVar >= 100) #

C

Which coded snippet below prints the numbers 10, 8, 6, 4, 2, and 0 in that order, one at a time, to the console? # A num = 10 while num > 0: print( num ) num = num - 1 # # B num = 10 while num >= 0: print( num ) # # C None of these provides the required output. # #D num = 10 while num >= 0: print( num ) num = num - 2 # #E num = 10 while num > 0: print( num ) #

D

Which code snippet below WILL NOT correctly print all element values of myList to the console? myList = [ 3, 7, 1, 9, 4, 0, 8 ] # A for i in range( len( myList ) ): print( myList[i] ) # # B for i in range(7): print( myList[i] ) # # C for i in myList: print(i) # # D for i in range( len( myList ) ): print( myList[i] ) # # E for i in myList: print( myList[i] ) # # F ALL snippets shown correctly print the elements of myList #

F

As programs become larger and more complex, it becomes less important to plan out how they will work before typing in the code. True or False

False

Computer memory is organized in a hierarchy. According to Lecture 2, main memory is the fastest to access. True or False

False

Consider the following for loop structure: for i in range(10): print("Doing Something") The loop iterator i will take on values from 1 to 10 (inclusive). True or False

False

Consider the following sequence of assignments. At the end, the value of y is 14. x = 2 y = 3 y += 7*x True or False

False

If the expression (myVar % myDigit != 0) evaluates to True, this means that myDigit is a factor of myVar. True or False

False

Imagine a program that had to process dates in a year. The following dates are "typical" cases: November 1 March 31 True or False

False

In Python, we must explicitly declare what type a variable will be before we create or initialize it. True or False

False

The arguments to the range constructor must be floats. True or False

False

The condition in the while statement is evaluated at the beginning and, if it is true, then all the indented code (loop body) is skipped. True or False

False

A Boolean variable is a variable that can take on the values of True or False.

True

A and B The and operator returns True if both A and B are True, otherwise it returns False. True or False

True

a = [1, 2, 3] b = [4, 5, 6] c = a+b b[1] = 10 d=b+c a = [ ] print(a) What would the outcome be

[ ]

a = [1, 2, 3] b = [4, 5, 6] c = a+b b[1] = 10 d=b+c a = [ ] print(c) What would the outcome be?

[1, 2, 3, 4, 5, 6]

a = [1, 2, 3] b = [4, 5, 6] c = a+b b[1] = 10 d=b+c a = [ ] print(d) What would the outcome be?

[4, 10, 6, 1, 2, 3, 4, 5, 6]

a = [1, 2, 3] b = [4, 5, 6] c = a+b b[1] = 10 d=b+c a = [ ] print(b) What would the outcome be?

[4, 10, 6]

num_items = 7 my_string = "" # empty string if num_items > 3: my_string = my_string + 'a' elif num_items < 10: my_string = my_string + 'c' else: my_string = my_string + 'm' print((my_string + 'd'), end = '!')

ad!

Temperature = 100is_hot = (Temperature > 85) What is the type of variable is_hot?

boolean

The "while" statement lets us create a loop while condition: things to do The condition is a _________ literal, variable, or expression that will be evaluated at the beginning of each possible repetition.

boolean

x = 'True' What is the type of variable x?

string


Ensembles d'études connexes

Trådløs kommunikasjon , bluetootj

View Set

Engineering Management Midterm 1

View Set

CSCFFS 2260: Credit Cards and Consumer Loans

View Set

Chapter 4 Nursing Care of Patients Having Surgery

View Set

Mastering Biology Ch. 12 (Mitosis)

View Set