Programming final

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

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is min(list1) ?

1

What number is displayed by the following segment? s = "178, 187, 398, 234" items = s.split(",") print(items[2])

398

What is len("Good") ?

4

What will be assigned to the string variable pattern after the execution of the following code? i = 1 pattern = 'a' * (5*i)

'aaaaa'

Given a string s = "Programming is fun", what is s.find('rom') ?

-1

Suppose list1 is [1, 3, 2, 4, 5, 2, 1, 0], what is list1[-1] ?

0

This is the first index in a list.

0

This is the first index in a string.

0

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

0 through 7

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is list1.index(5)?

2

What will be displayed by the following code? myList = [1, 2, 3, 4, 5, 6] for i in range (1, 6): myList[i-1] = myList[i] for i in range (0, 6): print(myList[i], end =" ")

2 3 4 5 6 6

Given the following function definition, what would the statement print(magic(5)) display? def magic (num): return num + 2*10

25

What will be displayed by the following code? def f (x = 1, y = 2): return x + y, x - y x , y = f1(y = 2, x = 1) print (x, y)

3 -1

What will be displayed by the following code? x = 1 def f1(): x = 3 print(x) f1() print(x)

3 1

Suppose list1 is [1, 2, 3], what is sum(list1) ?

6

Suppose list1 is [3, 4, 5, 20, 5, 25, 1, 3], what is len(list1)?

8

A variable defined inside a function is referred to as ______.

A local variable

What is the value of the variable string after the execution of the following code? string = 'abcd' string.upper()

ABCD

A(n) _______ is a piece of data that is sent into a function.

Argument

A Python string literal is always enclosed in double quotes.

False

A function's return data type must be the same as the function's parameters.

False

A local variable can be accessed from anywhere in the program.

False

Calling a function and defining a function mean the same thing.

False

Given a string s = "Programming is fun", what is s.startswith('m') ?

False

Indexing starts at 1, so the index of the first element is 1, the index of the second element is 2, and so forth.

False

The isupper method converts a string to all uppercase characters.

False

The strip() method returns a copy of the string with all leading whitespace characters removed, but does not remove trailing whitespace characters.

False

list1 = [11, 2, 23] and list2 =[2, 11, 23], list1 == list2 is ______.

False

The first line in the function definition is known as the function _____.

Header

Which step creates a connection between a file and a program?

Open the file

Arguments to functions always appear within _______.

Parenthesis

A value-returning function is ______.

a function that will return a value back to the part of the program that called it.

What does the following statement mean? num1, num2 = getNum()

The function getNum() is expected to return a value each for num1 and num2.

This string method returns true if a string contains only numeric digits and is at least one character in length.

The isdigit method

What will be displayed by the following code? x = 1 def f(): x = x +2 print(x) f() print(x)

The program has a runtime error because X is not defined

What will be displayed by the following code? def f1(x = 1, y = 2): x = x + y y += 1 print(x, y) f1(x, y)

The program has a runtime error because x and y are not defined

This is the last index in a list.

The size of the list minus one

A function in Python can return more than one value.

True

A(n) sequential access file retrieves data from the beginning of the file to the end of the file.

True

Different functions can have local variables with the same names.

True

Given a string s = "Programming is fun", what is s.endswith('fun') ?

True

It is possible to create a while loop that determines when the end of a file has been reached.

True

One reason for using functions is to break programs into manageable units or modules.

True

Python allows for passing multiple arguments to a function.

True

Python function names follow the same rules for naming variables.

True

The function header marks the beginning of the function definition

True

The term "input" file is used to describe a file from which the program gets data.

True

Which of the following should be defined as a void function?

Write a function that prints integers from 1 to 100.

"Welcome to Python".split() is ________.

["Welcome", "to", "Python"]

Suppose list1 =[0.5*x for x in range(0, 4)], list1 is _______.

[0.0, 0.5, 1.0, 1.5]

What would be the value of the variable list after the execution of the following code? list = [1, 2, 3, 4] list [3] = 10

[1, 2, 3, 10]

What will be displayed by the following code? def f(i, values = []) values.append(i) return values def main(): f(1) f(2) v = f(3) print(v) main()

[1, 2, 3]

What will be displayed by the following code? def f(value): values[0] = 44 def main(): v = [1, 2, 3] f(v) print(v) main()

[44,2,3]

Suppose x = 'b'. What will be displayed by the statement print (chr (ord (x) + 1)) ?

c

Which of the following function header is correct?

def f(a =1, b = 1, c = 2):

This term refers to an individual item in a list.

element

This function causes a program to terminate, regardless of which function or control mechanism is executing.

exit()

This is operator determines whether one string is contained inside another string.

in

This is a number that identifies an item in a list.

index

Before a file can be used by a program, it must be

opened

In a value-returning function, the value of the expression that follows the key word _____ will be sent back to the part of the program that called that function.

return

What of the following can not be used to convert a string of digits into number?

str

Which method could be used to convert a numeric value to a string?

str


Kaugnay na mga set ng pag-aaral

Managerial Accounting Chapter 20

View Set

Financial Mathematics- Unit 1: Income and Expenses

View Set

Ch.6, 7 International Marketing Quiz

View Set