Python

Ace your homework & exams now with Quizwiz!

Apply what you have learned in Unit 1 about data types, operands, functions, and conditions in simple Python programs to answer the following question: This Python script checks whether a number is even or odd. Which operand would be most appropriate for condition in line 2? 1 num=____(input("Enter your age")) 2 if num__==0: 3 print("Number is Even") 4 else: 5 print("____________")

"%2"

Suppose you have a list defined in the following way: myList = [[9, 8], [7, 6], [5, 4], [3, 2]] What are the correct dimensions of this list?

4 x 2

Which of these describes the Python data type float?

A numeric value consisting of postive or negative numbers containing decimals

Who or what usually finds logical errors?

A programmer

What number system contains both digits and characters?

Base 16

Base 10 numbers are also called?

Decimal

Which conditional statement allows you to check multiple expressions for TRUE?

elif

Which statement is the simplest form of a conditional statement?

if

Apply what you have learned in Unit 1 about data types, operands, functions, and conditions in simple Python programs to answer the following question: This Python script checks whether a number is even or odd. Which casting function would be most appropriate for line 1? 1 num=____(input("Enter your age")) 2 if num__==0: 3 print("Number is Even") 4 else: 5 print("____________")

int

The files that make up your Replit project are shown in the __________.

left pane

The __________ order of statements is important for a program to function as expected.

logical

How would you assign the following string to a variable named myString? Programming is fun

myString = "Programming is fun"

Which of these programs would produce the output shown below? linesPython is great Python is great Python is great Python is great

myString = 'Python is great \n' lines = 4 result = 'lines' + lines * myString print(result)

The Right pane of the Replit IDE is the __________.

output sandbox

Which expression would produce the following result if a="Python"? PythonPythonPythonPython

print(a * 4)

After clicking the "new repl" button, you would name your project in the _________ field.

title

Apply what you have learned in Unit 1 about data types, operands, functions, and conditions in simple Python programs to answer the following question: This Python script checks whether a number is even or odd. Which message would be most appropriate as output for line 5? 1 num=____(input("Enter your age")) 2 if num__==0: 3 print("Number is Even") 4 else: 5 print("____________")

"Number is Odd"

Which of the following is a valid code comment in Python?

#This is a valid code comment

What will happen when the following script is run? a = 1 b = 2 c = 3 d = 0 if a > b: d = 4 else: if a > c: d = 5 print(d)

0 will be printed

Which expression would solve 10 raised to the 2nd power?

10**2

Consider the expression: c=a+b If a = '10' and b = '10', what would be the result of the expression?

1010

1 grade = 71 2 if grade > 90: 3 print("You got an A") 4 elif grade > 80: 5 print("You got a B") 6 elif grade > 70: 7 print("You got a C") 8 elif grade > 60: 9 print("You got a D") 10 elif grade <= 60: 11 print("You got a F") 12 print("We are done!") For the sample program, when using the interactive debugger with breakpoints set on lines 2,4,6,8, and 10, what line number is highlighted when the grade message is displayed as output?

12

Consider this expression: 4*2**2 What is its value ?

16

Suppose you have a list defined in the following way: myList = [[9, 8, 7, 6], [5, 4, 3, 2]] What are the correct dimensions of this list?

2 x 4

1 grade = 71 2 if grade > 90: 3 print("You got an A") 4 elif grade > 80: 5 print("You got a B") 6 elif grade > 70: 7 print("You got a C") 8 elif grade > 60: 9 print("You got a D") 10 elif grade <= 60: 11 print("You got a F") 12 print("We are done!") In order to debug every possible path in the example code, a breakpoint would need to be set on which line numbers?

2,4,6,8,10

Which operator would be used to find the remainder of 20 divided by 10?

20%10

Suppose you have a list defined in the following way: myList = [[9, 8, 7], [6, 5, 4], [3, 2, 1]] What are the correct dimensions of this list?

3 x 3

What will happen when the following script is run? a = 10 b = 2 c = 3 d = 0 if a > b: d = 4 else: if a > c: d = 5 print(d)

4 will be printed

What will happen when the following script is run? a = 5 b = 15 c = 10 d = 0 if a > b: d = 4 elif b > c: d = 5 else: d = 6 print(d)

5 will be printed.

1 grade = 71 2 if grade > 90: 3 print("You got an A") 4 elif grade > 80: 5 print("You got a B") 6 elif grade > 70: 7 print("You got a C") 8 elif grade > 60: 9 print("You got a D") 10 elif grade <= 60: 11 print("You got a F") 12 print("We are done!") For the sample program, when using the interactive debugger with breakpoints set on lines 2,4,6,8, and 10, what is the line number of the breakpoint that the interactive debugger will step into a condition?

6 or 7

1 price = 12 2 quantity = 2 3 amount = price*quantity 4 5 if amount > 100: 6 if amount > 500: 7 print("Amount is greater than 500") 8 else: 9 if amount < 500 and amount > 400: 10 print("Amount is between 400 and 500") 11 elif amount < 500 and amount > 300: 12 print("Amount is between 300 and 500") 13 else: 14 print("Amount is between 200 and 500") 15 elif amount == 100: 16 print("Amount is 100") 17 else: 18 print("Amount is less than 100") Using the interactive debugger for the sample script, which line(s) would you set a breakpoint on to test the nested if statements?

6,9

Consider this program. Which score represents an edge case that should be tested? score = 70 if score > 90 and score <= 100: print('You got an A! Congrats!') elif score > 80 and score <= 90: print('You got a B! Well done!') elif score > 70 and score <= 80: print('You got a C.') else: print("You did not pass the exam.")

80

A return value of 1 would be possible for which of the following value pairs (using the Boolean operator "and")?

A= TRUE, B=TRUE

Which value pair will return True using the Boolean operator "and"?

A= TRUE, B=TRUE

Which term refers to the sequence of steps to solve a problem?

Algorithm

A user that inputs 1 and 3 into the following code will result in what output? board = [ ["-", "-", "-"], ["-", "-", "-"], ["-", "-", "-"] ] col = int(input("X player, select a column: ")) row = int(input("X player, select a row: ")) board[row][col] = "X" print(board[0]) print(board[1]) print(board[2])

An error since the index is out of range.

What is the result of this code? my_first_list = ['a', 'b', 'c'] my_second_list = ['d', 'e', 'f', 'g'] my_third_list = my_first_list - my_second_list my_third_list.extend('h') print (my_third_list[2:6])

An error, because subtraction (-) is not an operator that works on lists.

Where in an if-elif chained conditional statement is an else statement located to catch any cases that did not satisfy any of its criteria?

At the end.

Decimal values are also called what?

Base 10 numbers

What number system is represented by 0 and/or 1?

Binary

True or False values are which Python data type?

Boolean

What is a Python data type that consists of either True or False?

Boolean

Which built-in string method can be used to convert the first character of a string to uppercase and all remaining characters to lowercase?

Capitalize

__________ is the first step in programming.

Defining the problem

The process used by developers to solve a problem is called what?

Development cycle

The Boolean type has two possible values (True or False), which can also be represented numerically with 0 or 1. The numeric 0 represents which Boolean value?

FALSE

Using the Boolean operator "and", if A = True and B = False, what would the result be?

FALSE

Select the Python data type that consists of positive or negative numbers that have decimal values.

Float

A block of code that only runs when it is called is a(n)?

Function

Which set of operations represents the correct order of a typical computer program?

Input-Process-Output

Which best describes the output operation?

It displays results.

What is the output of the following program? temp_Fahrenheit = 36 if temp_Fahrenheit < 32: print('It is cold outside') elif temp_Fahrenheit > 80: print('It is hot outside') else: pass print('It must be a nice day')

It must be a nice day

myType = [1, 2, "car", True] What collection type is created in the code snippet above?

List

Which of the following options is a property of Python lists?

List elements can be accessed by an index value.

Which of the following options is a property of Python lists?

Lists are ordered.

Which of the following options is a property of Python lists?

Lists can contain any number of elements.

A miscalculation resulting from an error in the order of operations is which type of error?

Logic

__________ define(s) how steps should be arranged so that a program can complete a task correctly.

Logic

Function names are followed by which symbols?

Parenthesis

Why is it important to look for patterns when solving a problem and designing an algorithm?

Patterns reduce the number of steps it takes to get to a solution

Which term refers to the English-like statements used to describe the steps in a program or algorithm?

Pseudocode

myType = {1, 2, "car", True} What collection type is created in the code snippet above?

Set

What is the built-in string method that changes the case of every character in a string?

Swapcase

If a programmer forgets to put the closing bracket on a print statement, what type of error will result?

Syntax

What are the grammar rules that define a programming language referred to as?

Syntax

Which error type would be generated as a result of attempting to use a reserved keyword as a variable name?

Syntax

Using the Boolean operator "or", if A = False and B = True, what would the result be?

TRUE

What happens if an exception is not handled?

The program will halt and generate an error.

What will happen in a program if there is an error that is not handled by a try/except statement?

The program will terminate and raise an error.

myType = (1, 2, "car", True) What collection type is created in the code snippet above?

Tuple

What is the process used to convert a literal of one type to another called?

Type casting

Attempting to operate on variables with incompatible data types is an example of which error type?

TypeError

What should be considered first when designing an algorithm?

What are the inputs?

Where can a nested conditional statement appear within an if-elif chained conditional statement?

Within either the if or elif statement.

A user that inputs 1 and 2 into the following code will result in what output? board = [ ["-", "-", "-"], ["-", "-", "-"], ["-", "-", "-"] ] col = int(input("X player, select a column: ")) row = int(input("X player, select a row: ")) board[row][col] = "X" print(board[0]) print(board[1]) print(board[2])

['-', '-', '-'] ['-', '-', '-'] ['-', 'X', '-']

A user that inputs 2 and 1 into the following code will result in what output? board = [ ["-", "-", "-"], ["-", "-", "-"], ["-", "-", "-"] ] col = int(input("X player, select a column: ")) row = int(input("X player, select a row: ")) board[row][col] = "X" print(board[0]) print(board[1]) print(board[2])

['-', '-', '-'] ['-', '-', 'X'] ['-', '-', '-']

What should the result of this code be? my_list = ['pear','orange','pineapple','apple','peach','kiwi','banana'] my_other_list = my_list my_other_list.sort() print(my_other_list)

['apple','banana','kiwi','orange','peach','pear','pineapple']

What should the result of this code be? my_list =['pear','orange','pineapple','apple','peach','kiwi','banana'] my_other_list = my_list my_other_list.sort() print(my_list) print(my_other_list)

['apple','banana','kiwi','orange','peach','pear','pineapple'] ['apple','banana','kiwi','orange','peach','pear','pineapple']

What should the result of this code be? my_list = ['pear','orange','pineapple','apple','peach','kiwi','banana'] my_other_list = my_list[1:5] my_other_list.sort() print(my_other_list)

['apple','orange','peach','pineapple']

What is the result of this code? my_first_list = ['a', 'b', 'c'] my_second_list = ['d', 'e', 'f', 'g'] my_third_list = my_first_list + my_second_list my_third_list.extend('h') print (my_third_list[1:5])

['b', 'c', 'd', 'e']

What is the result of this code? my_first_list = ['a', 'b', 'c'] my_second_list = ['d', 'e', 'f', 'g'] my_third_list = my_first_list * 3 my_third_list.extend('h') print (my_third_list[5:])

['c', 'a', 'b', 'c', 'h']

The first step in designing any program is to __________.

determine the purpose of the program

The __________ conditional statement catches anything not caught by the preceding conditions.

else

This script checks whether a person is eligible for voting or not. Which condition statement is missing on line 4? 1 age=int(input("Enter your age")) 2 if ___ >=18: 3 print("_____ for voting") 4 ____: 5 print("not eligible for voting")

else

Which statement follows a try statement and is responsible for handling an error?

except

Algorithms consist of a(n) ____________ number of instructions.

finite

A(n) ___________ data type consists of positive or negative numbers and does not have any decimals.

integer

Read the following programs carefully. Which of these programs would produce the output shown below? 555552 3

myVar1 = '3' myVar2 = '2' lines = int(myVar1) + int(myVar2) myStr = myVar2 + ' ' + myVar1 + '\n' result = str(lines) * lines + myStr print(result)

How would you output the string literal "Programming is fun" to the screen?

print("Programming is fun")

How would you check for the existence of the word "brown" in the following sentence? "the brown fox jumped over the lazy dog"

print("brown" in "the brown fox jumped over the lazy dog")

How would you modify the following expression to print each word on a separate line? print("hello world")

print("hello\nworld")

How would you construct a print statement to print the following quote? Programming isn't about what you know; it's about what you can figure out

print('Programming isn\'t about what you know; it\'s about what you can figure out')

This script checks whether a person is eligible for voting or not. Which function would be used to display a message to the user on line 3? 1 age=int(input("Enter your age")) 2 if ___ <=18: 3 ____("Eligible for voting") 4 ____: 5 print("not eligible for voting")

print()

How could you simplify the following expression? print(2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2 * 2)

print(2**10)

Which example would convert the following variable containing an integer to a string? a=123

print(str(a))

In order to execute your code in Replit you select the ________ button.

run

Which is a valid assignment of a string to a variable?

sayHello = "Hello, world"

It is important that each individual __________ in an algorithm be well defined.

step

After determining the inputs and outputs, the next step when designing an algorithm is to determine __________.

the order of the algorithm steps

Which statement is used to check for errors in your Python code?

try


Related study sets

APChem Unit 4 topic questions 4.7-4.8

View Set

ATI psych treatment setting/communication

View Set

(PrepU) Health Promotion: Nursing Concepts

View Set

Ch 5 Q's, Ch 6 Questions, test #3 - Online practice work, test #3 - Stats & Methods

View Set

CHAPTER 2 Quiz: The Courts and Jurisdiction

View Set

rest of the ap chem ms buck questions

View Set