Final Exam Study Guide

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

What will the result be? x = 8 y = 9 print(not(not(x < 3) and not (y > 14 or y > 10))) A. True B. False C. Running these commands will result in an error D. No output will be printed

B. False

Numpy.array(list) does what? A. It converts array to list B. It converts list to array C. It converts array to array D. None of the above

B. It converts list to array

You're a professor teaching Data Science with Python, and you want to visually assess if longer answers on exam questions lead to higher grades. Which chart would you use? A. Line plot B. Scatter plot C. Histogram D. Pie chart

B. Scatter plot

What is the output? aList = [10, 20, 30, 40, 50, 60, 70, 80] print(aList[2:5]) print(alist[:4]) print(alist[3:]) A. [20, 30, 40, 50] [10, 20, 30, 40] [30, 40, 50, 60, 70, 80] B. [30, 40, 50] [10, 20, 30, 40] [40, 50, 60, 70, 80] C. [20, 30, 40] [10, 20, 30, 40] [30, 40, 50, 60, 70, 80] D. None of the above answers are correct

B. [30, 40, 50] [10, 20, 30, 40] [40, 50, 60, 70, 80]

What is the output? aList = [4, 8, 12, 16] aList[1:4] = [20, 24, 28] print(aList) A. [4, 20, 24, 28, 8, 12, 16] B. [4, 20, 24, 28] C. [20, 24, 28, 16] D. [4, 8, 12]

B. [4, 20, 24, 28]

What is the output? import numpy as np x = [4, 9, 6, 3, 1] y = np.array(x) high = y > 5 print(y[high]) A. [9, 6] B. [9 6] C.[False, True, True, False, False] D. [False True True False False]

B. [9 6]

Which of these is the correct code for creating a list of names? A. nameList = John, Harry, Jesse, John, Harry, Harry B. nameList = ('John', 'Harry', 'Jesse', 'John', 'Harry', 'Harry') C. nameList = ['John', 'Harry', 'Jesse', 'John', 'Harry', 'Harry'] D. nameList = [John, Harry, Jesse, John, Harry, Harry]

C. nameList = ['John', 'Harry', 'Jesse', 'John', 'Harry', 'Harry']

Which is the correct way to copy the aList to newList and any changes made in the original list WILL NOT affect the newList? aList = ['a', 'b', 'c', 'd'] A. newList = copy(aList) B. newList = aList() C. newList = list(aList) D. newList = aList

C. newList = list(aList)

How do we install NumPy in the system? A. intall numpy B. pip install python numpy C. pip install numpy D. pip install numpy python

C. pip install numpy

What is the output? fam = [1.73, 1.89, 1.68, 1.71, 1.89, 1.76] tallest = max(fam) print(fam.count(tallest)) A. error B. 1.89 C. 1 D. 2

D. 2

What is the output? import numpy as np a = np.array([1, 2, 3, 5, 8]) b = nparray([0, 3, 4, 2, 1]) c = a + b c = c * a print(c[2]) A. 7 B. 12 C. 10 D. 21

D. 21

For which applications can you use Python? A. You want to do some quick calculations. B. For your new business, you want to develop a database-driven website. C. Your boss asks you to clean and analyze the results of the latest satisfaction survey. D. All of the above.

D. All of the above.

To import pyplot module we can write: A. Import pyplot as plt B. Import matplotlib.pyplot C. Import matplotlib.pyplot as plt D. Both B and C

D. Both B and C

What is the output? var1 = 1 var2 = 2 var3 = '3' print(var1 + var2 + var3) A. 6 B. 33 C. 1+2+3 D. Error

D. Error

When should a "while" loop be used? A. When taking guesses from a user B. When one wants to change the order of execution of statements C. When a statement evaluates to 'false' D. When one doesn't know in advance how many iterations would be needed to perform a repeated operation

D. When one doesn't know in advance how many iterations would be needed to perform a repeated operation

What does the following code print? stuff = ['a', 'b', 'c'] stuff.insert(1, 'water') print(stuff) A. ['a', 'b', 'c', 'water'] B. ['a', 'b', 'c', 1, 'water'] C. ['water', 'a', 'b', 'c'] D. ['a', 'water', 'b', 'c']

D. ['a', 'water', 'b', 'c']

What is is output? import numpy as np x = np.array([True, True, False, False]) y = np.array([True, False, True, False]) z = np.array(False, False, False, True]) print(np.logical_or(np.logical_and(x,y),x)) A. True B. False C. [True False False False] D. [True False False True]

D. [True False False True]

Suppose you want to use the function inv(), which is in the linalg subpackage of the scipy package. You want to be able to run my_inv([[1, 2], [3, 4]]) Which import statement will you need in order to run the above code without an error? A. import scipy B. import scipy.linalg C. from scipy.linalg import my_inv D. from scipy.lanly import inv as my_inv

D. from scipy.lanly import inv as my_inv

Which method should we use to loop through both keys and values in a Python dictionary? A. keys() B. values() C. iterrows() D. items()

D. items()

What is the output? num1 = 65 num2 = 42 if num1 <= num2 : print('output A') else : print('output B') A. 65 B. 42 C. output A D. output B

D. output B

What is the output? print(df.iloc[2:5]) A. prints the 2nd, 3rd, 4th,5th columns of the dataframe df B. prints the 2nd, 3rd, 4th columns of the dataframe df C. prints the 2nd, 3rd, 4th rows of the dataframe df D. prints the 3rd, 4th, 5th rows of the dataframe df

D. prints the 3rd, 4th, 5th rows of the dataframe df

Select the correct way to print Emma's age. student = {1 : {'name' : 'Emma', 'age' : '27', 'sex' : 'Female'}, 2 : {'name' : 'Mike', 'age' : '22', 'sex' : 'Male'}} A. student[0][1] B. student['Emma']['age'] C. student[0]['age'] D. student[1]['age']

D. student[1]['age']

Which of the following codes can be used to get the data for the 'capital' and 'area' of Brazil? country capital area pop. BR Brazil Brasilia 8.516 200.40 RU Russia Mosco 17.100 143.100 IN India New_Delhi 3.289 1252.00 CH China Beijing 9.597 1357.00 SA South Africa Pretoria 1.221 59.98 A. df.loc['BR', 'capital', 'area'] B. df.loc[['BR'], ['capital', 'area'] C. df.loc[['Brazil', ['capital', 'area']] D. df.loc[['capital', 'area']]

B. df.loc[['BR'], ['capital', 'area']

Which of the following function should you use if you want to access the index information when iterating? A. index() B. enumerate() C. label() D. count()

B. enumerate()

What is the correct syntax to output the type of a variable or object in Python? A. print(typeOf(x)) B. print(type(x)) C. print(type x) D. print(typeof(x))

B. print(type(x))

Select the correct way to empty a dictionary. A. sampleDict = dict() B. sampleDict = {} C. sampleDict = [] D. sampleDict = ()

B. sampleDict = {}

What is the output? import numpy as np A1 = [1, 22, 33] A2 = ['Hello', 'my', 'friend'] A3 = [11, 3, 2020] D = np.array([a1, a2, a3]) print(D[2,1]) A. [11, 3, 2020] B. 'my' C. '3' D. 'hello'

C. '3'

Have a look at the four Python expressions below. Which one of these will throw an error? A. 'I can add integers, like' + str(5) + 'to strings' B. 'I said' + ('Hey' * 2) + 'Hey!' C. 'The correct answer to this multiple choice question is answer number' + 2 D. True + False

C. 'The correct answer to this multiple choice question is answer number' + 2

What is the output for the following code? x = 'you are doing well' print(len(x)) A. error B. 15 C. 18 D. 20

C. 18

What is the output? import numpy as np x = np.array([15, 20, 35, 40, 55, 60, 75]) print(np.median()) A. 35 B. 37.7 C. 40 D. 42.85

C. 40

Which of the following is NOT a comparison operator? A. >= B. <= C. AND D. !=

C. AND

How do you create a variable with the numeric value 5? A. x = int(5.5) B. x = 5 C. Both answers are correct

C. Both answers are correct

You're a professor teaching Data Science with Python, and you want to visually assess if the grades on your exam follow a particular distribution. Which chart would you use? A. Line plot B. Scatter plot C. Histogram D. Pie Chart

C. Histogram

What do comparison operators return? A. Whether two things are equal or not B. They return a number C. They return either True or False D. They return Yes or No

C. They return either True or False

How do we differentiate the body of the loop from the rest of the code? A. Writing loop with proper brackets B. Writing loop below the whole code C. Using proper indentation D. All are correct

C. Using proper indentation

In the given chart, box surrounded with red border is called (Sale Report chart) A. Y ticks B. X label C. Y label D. Y legend

C. Y label

What is the output? import numpy as np names = np.array['Reem', 'Salah', 'Haya', 'Maryam', 'Fatema'] print(names[2 : 4]) A. ['Haya' 'Maryam' 'Fatema'] B. ['Reem' 'Salah' 'Haya'] C. ['Haya' 'Maryam'] D. ['Salah', 'Haya', 'Maryam']

C. ['Haya' 'Maryam']

What is the correct output of the following list operation? sampleList = [10, 20, 30, 40, 50] print(sampleList[-4 : -1] A. 20 B. [50, 40, 30, 20] C. [20, 30, 40] D. [10, 30, 40, 50]

C. [20, 30, 40]

To get help in the complex() function, for example, you can use help(complex). No you obtain the following information about the complex() function: class complex(object) complex(real[, imag]) -> complex number Create a complex number from a real part and an option This is the equivalent to (real + imag*1j) where imag defaults to 0. Which of the following statements is true? A. complex() takes exactly two arguments: real and [, imag]. B. complex() takes two arguments: real and imag. Both arguments are required. C. complex() takes two arguments: real and imag, where real is a required argument, imag is an optional argument. D. complex() takes two arguments: real and imag. If you don't specify imag, it is set to 1 by Ptyhon.

C. complex() takes two arguments: real and imag, where real is a required argument, imag is an optional argument.

Select the correct way to remove the key 'marks' from a dictionary. student = {'name' : 'Emma', 'class' : 9, 'marks' : 75} A. student.remove['marks'] B. del student('marks') C. del student['marks'] D. student.remove['marks']

C. del student['marks']

Which is NOT a valid way of accessing data from the following Pandas DataFrame named df. value a -0.751240 b 1.467381 c -0.557896 d 1.173745 e -0.932718 A. df.loc['a'] B. df.loc[['a']] C. df.loc['a', 'b'] D. df.loc['a' : 'c']

C. df.loc['a', 'b']

Given the following pandas DataFrame, which code will select only those people with salary greater than 94000? Supposed the pandas DataFrame is stored in df. Name Age Salary Job 0 Rachel 30 100000 Designer 1 Monica 35 93000 Chef 2 Phoebe 37 88000 Masus 3 Ross 33 120000 Palentology 4 Chandler 34 94000 IT 5 Joey 30 95000 Artist A. df['Salary'>94000] B. df['Salary']>94000 C. df[df['Salary']>94000]

C. df[df['Salary']>94000]

Which of the following is the correct way to add number 4 as another element to mylist? mylist = [3, 6, 9, 8, 7] A. mylist + 4 B. mylist + '4' C. mylist + [4] D. mylist + ['4']

C. mylist + [4]

What is the output? if 3 < 4: print('A') else: print('B') print('C') A. A B. A C C. C D. B C

B. A C

What is the output? import pandas as pd data = { 'firstname': ['Sally', 'Mary', 'John'], 'age': [50, 40, 30] } df = pd.DataFrame(data) for lab, row in df.iterrows(): pring(row['firstname']) A. firstname age B. Sally 50 C. Sally, Mary, John D. 50, 40, 30

C. Sally, Mary, John

What are the correct types for the following variables: a, b, and c a = 3.0 b = str(a) c = False A. a is of type int, b is of type str, c is of type bool B. a is of type float, b is of type bool, c is of type str C. a is of type float, b is of type str, c is of type bool D. a is of type int, b is of type bool, c is of type str

C. a is of type float, b is of type str, c is of type bool

What is a correct syntax to return the shape of an array? (Suppose the name of the array is arr) A. shape(arr) B. arr.shape() C. arr.shape D. all of the above answers are correct

C. arr.shape

Which code should we use to display our graphs? A. plt.display() B. plt.graph() C. plt.show() D. plt.chart()

C. plt.show()

How many iterations will the loop run? x = 'abcdef' i = 'a' while i in x : print('i') A. 0 B. 1 C. 6 D. The loop will run forever (never stop)

D. The loop will run forever (never stop)

In Python, Dictionaries are immutable. True False

False

Items are accessed by their position in a dictionary and All the keys in a dictionary must be of the same type. True False

False

How do you insert COMMENTS in Python code? A. #This is a comment B. //This is a comment C. /*This is a comment*/ D. All of the above

A. #This is a comment

Which is NOT a legal variable name in Python? A. myvar B. my-var C. my_var D. _myvar

B. my-var

What will be printed? import numpy as np arr = np.array([41, 42, 43, 44]) x = arr > 42 print(x) A. [43, 44] B. [41, 42, 43, 44] C. [False True True True] D. [False False True True}

D. [False False True True}

What do comparison operators do> A. Compare two or more things B. Add items in comparing lists C. Compare two things D. Relate two things

A. Compare two or more things

Based on the plot shown, what can we interpret? (World Development in 2000) A. The countries in blue, corresponding to Africa, have both low life expectancy and a low GDP per capita. B. There is a negative correlation between GDP per capita and life expectancy. C. Chine has both a lower GDP per capita and lower life expectancy compared to India. D. All of the above answers are correct.

A. The countries in blue, corresponding to Africa, have both low life expectancy and a low GDP per capita.

What is the output? sampleList = [10, 20, 30, 40] del (sampleList[0 : 6]) print(sampleList) A. [ ] B. Error: list index out of range C. [10, 20] D. 0

A. [ ]

Select the correct option to join two lists in Python listOne = ['a', 'b', 'c', 'd'] listTwo = ['e', 'f', 'g'] A. newList = listOne + listTwo B. newList = extend(listOne, listTwo) C. newList.extend(listOne, listTwo) D. None of the above is correct

A. newList = listOne + listTwo

What is the correct Pandas function for loading CSV files into a DataFrame? A. read_csv() B. read_file() C. readCSV() D. readFile()

A. read_csv()

By default hist() uses bin value of ____ A. 5 B. 10 C. 15 D. 20

B. 10

What is the output? round(2.14552233, 3) A. 2.145 B. 2.146 C. 2.14 D. 2.15

B. 2.146

Can you tell how many printouts the following loop will do? x = 1 while x < 4 : print(x) x = x + 1 A. 2 B. 3 C. 4 D. 6

B. 3

In histogram, which of the following describes the number of data points that falls within a range of given values? A. bin B. bins C. range D. range()

B. bins

Suppose a function called add() is in a package called adder. Which of the following code correctly show how to import add2 and 3? A. import adder result = add(2, 3) B. from adder import add result = add(2, 3) C. import add from adder result = add(2, 3) D. import adder as ad result = ad.adder(2, 3)

B. from adder import add result = add(2, 3)

Given the lists below, what will print[x[2][0]) return? x = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']] print(x[2][0] A. d B. g C. c D. e

B. g

Which of the following is the correct way to find the average value of x using the NumPy statistics function? import numpy as np x = [1, 4, 8, 10, 12] A. np.average(x) B. np.mean(x) C. average(np.x) D. np.x(mean)

B. np.mean(x)

Assume the Pyplot sub package is already imported as plt. To add a title in the chart, we use the function _____ A. plot.title('title of the chart') B. plt.title('title of the chart') C. plt.title(title of the chart) D. plot.title(title of the chart)

B. plt.title('title of the chart')

Find the output. i = 97 res = '' while i <= 121 : res = res + str(i) i = i + 17 print(res) A. '97' B. '9797' C. '97114' D. '97114131'

C. '97114'

Find the output: l = ['a', 'e', 'i', 'o', 'u'] org = 'Jperalta' count = 0 for i in org: if i in l: count = count + 1 print(count) A. 1 B. 3 C. 5 D. 7

C. 5

Which of the following is the correct way to iterate over all separate elements of a 2D NumPy array? A. for x in np.nditer(2D_array) : B. for x in 2D_array C. for x in np.2D_array D. for x in nditer(2D_array)

A. for x in np.nditer(2D_array) :

What is the correct file extension for Python files? A. .pt B. .py C. .pyt D. .pyth

B. .py

Which method is best used when adding an item to the end of a list? A. .insert() B. .add() C. .append() D. .attach()

C. .append()

Which of these is the best description of a list in Python? A. A list is a collection of data that has an order and can be changed. B. A list is a lot of variables. C. A list is used for shopping. D. A list is a collection of data that cannot hold duplicated data and cannot be changed.

A. A list is a collection of data that has an order and can be changed.

In NumPy, what does the SHAPE of an array mean? A. The shape is the number of elements in each dimension. B. The shape is the number of rows. C. The shape is the number of columns. D. The shape is the total number of elements in the array.

A. The shape is the number of elements in each dimension.

What is the output? fam = [1.89, 1.73, 1.68, 1.71, 1.89, 1.76] fam.append('me') fam.append(1.78) fam.reverse() print(fam) A. [1.78, 'me', 1.76, 1.89, 1.71, 1.68, 1.73, 1.89] B. [1.76, 1.89, 1.71, 1.68, 1.73, 1.89, 1.78, 'me'] C. [1.76, 1.89, 1.71, 1.68, 1.73, 1.89, 'me', 1.78] D. AttributeError: 'list' object has no attribute 'reverse

A. [1.78, 'me', 1.76, 1.89, 1.71, 1.68, 1.73, 1.89]

The following code produces which DataFrame? import pandas as pd df = pd.DataFrame({'a' : [4, 5, 6] 'b' : [7, 8, 9] 'c' : [10, 11, 12]}) print(df) A. a b c 0 4 7 10 1 5 8 11 2 6 9 12 B. a b c a 4 5 6 b 7 8 9 c 10 11 12 C. a b c 0 4 5 6 1 7 8 9 2 10 11 12 D. a b c a 4 7 10 b 5 8 11 c 6 9 12

A. a b c 0 4 7 10 1 5 8 11 2 6 9 12

What is a correct syntax to output "Hello World" in Python? A. print("Hello World") B. print("Hello World') C. echo("Hello World") D. print "Hello World"

A. print("Hello World")

Which message would be displayed if age is 16 and the registered status is 'Y'? if age < 17 print (' you are not old enough to drive') elif age >= 17 and registered == 'Y' print('you are old enough to drive') elif age >= 17 and registered != 'Y': print('you are old enough, but not registered to drive') else: print('error') A. you are not old enough to drive B. you are old enough to drive C. you are not old enough, but not not registered to drive D. error

A. you are not old enough to drive

What is the output? n = 25 print(n % 2 == 0 or n % 3 == 0) A. True B. False C. Error D. 1

B. False

Select the code that will graph schools on the x-axis, zone on the y-axis, with the title "School Survey" A. zone = [1, 2, 3, 4] schools = [230, 430, 300, 140] plt.plot(zone, school, 'School Survey') plt.show() B. zone = [1, 2, 3, 4] schools = [230, 430, 300, 140] plt.plot(schools, zone, 'School Survey') plt.show() C. zone = [1, 2, 3, 4] schools = [230, 430, 300, 140] plt.plot(zone, school) plt.title('School Survey') plt.show() D. zone = [1, 2, 3, 4] schools = [230, 430, 300, 140] plt.plot(schools, zone) plt.title('School Survey') plt.show()

D. zone = [1, 2, 3, 4] schools = [230, 430, 300, 140] plt.plot(schools, zone) plt.title('School Survey') plt.show()


Set pelajaran terkait

Chapter 14: Somatosensory Function, Pain, Headache

View Set

Bible Doctrines Final Enns Questions

View Set

Chapter 8: Confidence Interval Estimation

View Set

RE National Practice Exam Wrong Answers

View Set

research methods final (starred 8&9)

View Set