Teals Final Exam

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

What symbol can be used to comment out one line of code?

#

What is the output of the following code? print(str((1,2)) + 'Python' + '3')

(1, 2)Python 3

What is used to concatenate two strings in Python?

+ operator

What is the result of print(3 ** 3)?

27

What is output of the following program? def Moo(x): if (x == 1): return 1 else: return x + Moo(x - 1) print(Moo(2))

3

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

3

What is the output of the following code? num = 1 def func(): num = 3 print(num) fun() print(num)

3 1

What is the output of the following code? def myfunction(x, y): a= x * y return a print(myfunction(3,25))

75

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

8

What is the output of the following code? names = "{1}, {2} and {0}". format('John', 'Bill', 'Sean') print(names)

Bill, Sean, and John

Suppose list2 = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], What is list2[-1]?

H

What is used to define a block of code(body of loop, function etc.) in Python?

Indentation

What is the output of the following program? def printLine(text): print(text, 'is awesome. ') printLine('Python')

Python is awesome.

What is the output of the following code? print(3 >= 3)

True

If the following code is run in Python, what would be result? num= '5' * '5'

TypeError: can't multiply sequence by non-int of type 'str'

Which of the following is correct?

Variable name can start with an underscore

If list2 = ['A', 'B', 'C', 'D', 'E', 'F'], what is list2[0:2]?

['A','B']

What is the output of the following program? language = ['p', 'y', 't', 'h', 'o', 'n'] print(language[:-4])

['p','y']

What is the output of the following program? n = [x*x for x in range(4)] print(n)

[0, 1, 4, 9]

Suppose list3 = [1, 2, 3], what is list3 * 2?

[1,2,3,1,2,3]

What is the output of the following code? numbers = [2, 3, 4] print(numbers)

[2, 3, 4]

Which statement is true

a function is a piece of code that performs a specific task

The statement using and operator results true if ________

both operands are true

Which of the following keywords marks the beginning of the function block?

def

Which of the following is a valid way to start a function in Python?

def someFunction():

What is the output of the following code? crlist = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i'] print(crlist.pop(4)) print(crlist)

e ['a', 'b', 'c', 'd', 'f', 'g', 'h', 'i']

What keyword would you use to add an alternative condition to an if statement?

elif

If x = 5.6, what is type x?

float

Which one of the following is a valid Python if statement?

if a>=22

What is the output of the following code snippet? def myfunc(text, num): while num > 0: print(text) num = num -1 myfunc('Hello', 4)

infinite logo

What is used to take input from the user in Python?

input()

To add Z to the end of list2, use:

list2.append('Z')

To remove string C from list2, use:

list2.remove('C')

If list2 = ['R', 'Z', 'A', 'B'], how would you sort it alphabetically?

list2.sort()

If a statement is not used inside the function, the function will return:

none

What is the output of the following code? def my_function(): print(" THIS IS MY FUNCTION!")

nothing is printed to the screen

How can you change num = {'one': 'two': 3} to num = {'one': 1, 'two': 2}

num['two'] = 2

Which of the following enclose the input parameters or arguments of a function?

parenthesis

Which of the following functions print the output to the console?

print

How would you print the second item in the list variable "example"?

print(example(1))

Suppose w = "Welcome", what is type(w)?

str

In the following code, n is a/an________? n = '5'

string

Suppose a list named test contains 5 elements. How can you set 3rd element of test to 'Python'?

test[2]='Python'

Suppose a list with name test, contains 10 elements. You can get the 5th element from the test list using:

test[4]

If you have a variable "example", how do you check to see what type of variable you are working with?

type(example)

Select the argument(s) in the following code: def myfunction(x, y): a=x * y return a

x and y


Ensembles d'études connexes

Inquizitive - Synthesizing Ideas

View Set

ECON - 2302 Ch. 27, Ch 5 , Ch 6, Ch 28, Ch 21, Ch 32 Study Questions Final

View Set

Internet Service Providers (ISP)

View Set

Metrix Learning CompTIA A+ 220-1102 Review Questions

View Set

Grammar Unit 4- Identifying Types of Phrases

View Set