Business Programming Test 2 Python

¡Supera tus tareas y exámenes ahora con Quizwiz!

8

What is the output of the following code? k=10 k -= 2 print(k)

Which Python keyword indicates the start of a function definition?

def

A character or string used to indicate where a string should be split.

delimiter

Which of the following is not a valid loop in Python?

do while

What is the Python reserved word that is used in a two-way decision structure when the executed logical test is false?

else

If x is 5 then only the first statement will print: if x == 5 : print('Is 5) print('Is Still 5') print('Third 5')

false

Which function is way to remove an element from a list by index?

pop()

Which of the following is not a Python reserved word?

print

Which line of the following Python program is useless? def stuff(): print('Hello') return print('World') stuff()

print('World')

What type of error is caused by reading a string via bracket operator and the wrong index?

string index out of range

Which of the following elements of a mathematical expression in Python is evaluated first?

()

For the following code: astr = Hello Bob istr = 0 try: istr = int(astr) except: istr = -1 What will the value be for istr after this code executes?

-1

What is the output of below code: num = 42 if num % 2 == 0: print("Even Number") else: print("Odd Number")

Even Number

What is the output of below code: num = -33 if num > 0: print("Positive Number") else: print("Negative Number") #nested if if -33<=num: print("Two digit Negative Number")

Negative Number followed by Two digit Negative Number

What is the most important benefit of writing your own functions?

To avoid duplicate code To make the code run faster

Python comes with functions called ____________ functions.

built-in

In Python what is the input() feature best described as?

built-in function

exe dll

compiler with process the source code and generate a(n) ____________ file.

You use a ______________ which is a variable used in a loop to count the number of times something happened

counter

What do we do to a Python statement that is immediately after an if statement to indicate that the statement is to be executed only when the if statement is true?

indent the next line

Python provides a built-in function called _________ that gets input from the keyboard.

input

In the following Python code, which of the following is an argument to a function? x = banana y = max(x) print(y)

x

In the following Python code, which of the following is an argument to a function? x = banana y = max(x) print(y) Selected Answer:

x

"Assume the variable x has been initialized to an integer value (e.g., x = 3). What does the following statement do? x = x + 2"

"Retrieve the current value for x, add two to it and put the sum back into x"

Assume the variable x has been initialized to an integer value (e.g., x = 3). What does the following statement do? x = x + 2

"Retrieve the current value for x, add two to it and put the sum back into x"

For the following code: astr = Hello Bob istr = 0 try: istr = int(astr) except: istr = -1 What will the value be for istr after this code executes?

-1

What will the following code print out? smallest_so_far = -1 for the_num in [9, 41, 12, 3, 74, 15] : if the_num < smallest_so_far : smallest_so_far = the_num print(smallest_so_far)

-1

In the following code which will be the last line to execute successfully? (1) astr = Hello Bob ; (2) istr = int(astr); (3) print First , istr; (4) astr = 123 ;"

1

What is the output of below code: numbers = [1, 2, 3, 4] sol = 0 for val in numbers: sol = val * val print(sol)

1 4 9 16

What will the following Python code print out? def func(x) : print(x) func(10) func(20)

10 20

What does the following Python code return? (Note that this is a bit of a trick question and the code has what many would consider to be a flaw/bug so read carefully). def addtwo(a, b): added = a + b return a x = addtwo(2, 7) print(x)

2

What is the output of the following code? print(100/50)

2.0

What does the following Python program print out last? tot = 0 for i in [5, 4, 3, 2, 1] : tot = tot + 1 print(tot)

5

What will be the value of x after the following statement executes: x = 1 + 2 * 3 - 8 / 4

5

What signifies the begining of a statement block or suite in Python?

:

Which of these operators is not a comparison or logical operator?

=

In a Python program, a control structure is,

Directs the order of execution of the statements in the program

What is the output of below code: num = 42 if num % 2 == 0: print("Even Number") else: print("Odd Number")

Even Number

"In Python, a variable must be declared before it is assigned a value"

False

A special character used in files and strings to indicate the end of a line is called a nextline.

False

A string is a sequence of characters but you cannot access the characters with the bracket operator.

False

An iteration variable is used in a loop to help accumulate a sum, also know as an accumulator."

False

For the following code: if x < 2: print('Below 2') elif x >= 2: print'Two or more') else: print('Something else'). If the value of x is set to a number, print('Something else') will print out."

False

If x is 5 then only the first statement will print: if x == 5 : print('Is 5) print('Is Still 5') print('Third 5')

False

It is not possible to allow end users to select files in python.

False

Python is a strongly typed language in which you must declare your variables before use.

False

The break statement within a loop will cause the iteration to continue.

False

The max() funciton only works with number list.

False

The random function generates true random numbers not pseudorandom numbers.

False

The sum() funciton will work with numbers and letters.

False

What Boolean will be the output of the following: 12 != 12

False

Writing code and running it interactively stores the information processed in secondary memory.

False

Writing code and running it interactively stores the information processed in secondary memory.

False

You can use a variable in an expression without first declaring it.

False

What is the output of below code: num = 1000 if 9 < num < 99: print("Two digit number") elif 99 < num < 999: print("Three digit number") elif 999 < num < 9999: print("Four digit number") else: print("number is <= 9 or >= 9999")

Four digit number

What does the following code print out?

Hello There

What does the following code print out? def thing(): print('Hello') print('There')

Hello There

What is a good description of the following bit of Python code?; zork = 0 for thing in [9, 41, 12, 3, 74, 15] : zork = zork + thing print ('After , ' + str(zork))

Sum all the elements of a list

A function call is like a detour in the flow of execution. It executes then goes back the point of call.

True

A function is a named sequence of statements that performs a computation.

True

A program is a sequence of stored instructions

True

A sequence of instructions in a programming language is call Code.

True

One of Python's strengths is working with files and reading in data.

True

Repeative code is when the code block executes over and over until it is finished.

True

The continue statement within a loop will cause the iteration to continue

True

The following statement is a legal use of the is keyword : if smallest is None : smallest = value

True

The slice of this statement is: fruit = 'apple'; fruit[:3] returns 'app'.

True

Variable names can contain an underscore _ but should not start with one unless writing library code.

True

Variable names can contain an underscore _ but should not start with one unless writing library code.

True

We call the while statement an indefinite loop because it simply loops until some condition becomes False.

True

When you have multiple lines in an if block, you terminate that block by de-indent the next line past the if block to the same level of indent as the original if statement.

True

What do we do to a Python statement that is immediately after an if statement to indicate that the statement is to be executed only when the if statement is true?

indent the next line

Which of one of the following functions is concerned with getting information from the user?

input()

"In the following code, print(98.6). What is 98.6 ?"

number

Which one of these functions was NOT covered in Chapter 1 or 2?

random()

A segment of a string is called a __________.

slice

A sequence of characters stored in permanent storage like a hard drive is called a(n) __________.

text file

A boolean expression is an expression that is either true or false.

true


Conjuntos de estudio relacionados

Capitalization & Punctuation Rules

View Set

Chapter 12 Mastery Progress Exam

View Set

Ch. 9: Fat-Soluble Vitamins (Test 4)

View Set

Entrepreneurship Chapter 3 Review

View Set

AD Banker life and Health CHP 14

View Set

Chapter 2 - INFO 160 (Understanding Your Computer)

View Set

Infotech English For Computer Users Student's Book - Unit 15

View Set