Programming Midterm

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall with Kai
GameKnowt Play
New
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/61

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

62 Terms

1
New cards

The np.arange(5) function creates an array with values [0,1,2,3,4].

True

2
New cards

The loc function in Pandas selects rows and columns using integer-based indexing.

False

3
New cards

The pd.merge() function can perform inner, left, right, and outer joins

True

4
New cards

The plt.plot() function can be used to create both line and scatter plots.

True

5
New cards

In Python, lists are mutable, meaning they can be modified after creation

True

6
New cards

The append() method in Pandas permanently changes the DataFrame unless reassigned.

False

7
New cards

In NumPy, axis=0 usually refers to operations across rows.

True

8
New cards

The startswith() string method checks if a string begins with a specified substring

True

9
New cards

Using in with a list checks whether an element exists in that lost

True

10
New cards

The dropna() function in Pandas removes rows or columns with missing values

True

11
New cards

Which of the following creates a NumPy array of zeros with shape (2,3)?

np.zeros((2,3))

12
New cards

Which join returns only the rows with matching keys in both DataFrames?

Inner join

13
New cards

What does df.head(3) return?

First 3 rows of the DataFrame

14
New cards

Which of the following is correct about NumPy broadcasting?

It allows operations on arrays of different but compatible shapes.

15
New cards

Which Pandas method removes duplicate rows?

df.drop_duplicates()

16
New cards

Which function is used to calculate the square root in Python?

  1. math.sqrt()

  2. np.sqrt()

17
New cards

What is the default axis for df.sum() in Pandas?

axis=0 (column-wise)

18
New cards

Which code correctly selects the first two columns of a NumPy array arr?

arr[:,:2]

19
New cards

Which of the following creates a dictionary in Python?

{“A”:1, “B”:2}

20
New cards

What does df[‘Age’].mean() compute?

The average of the Age column

21
New cards

Which of the following closes a Matplotlib figure?

plt.close()

22
New cards

Which keyword is used to define a function in Python?

def

23
New cards

Which function returns the length of a list mylist?

len(mylist)

24
New cards

What does the following code return?:

“Hello World”.lower()

“hello world”

25
New cards

Which Pandas method displays basic statistics like mean, std, and count?

df.describe()

26
New cards

Applying np.sort(x, axis=0) to a 2D array sorts each row independently

False

27
New cards

In Matplotlib, calling plt.show() clears the current figure from memory.

True

28
New cards

Using plt.subplot(2,2,5) will raise an error.

True

29
New cards

The default x-values in plt.plot([2,4,6]) will be [0,1,2]

True

30
New cards

plt.plot() can only plot a single line at a time

False

31
New cards

We have to use random.seed(42) ensures the random numbers generated can be replicated.

True

32
New cards

pow(x,y) and x ** y return the same result in Python

True

33
New cards

The math module is automatically available in Python

False

34
New cards

Which parameter in plt.savefig() controls image resolution?

dpi

35
New cards

Which statement about np.reshape() is correct?

Cannot reshape in place

36
New cards

Suppose x = nparange(12).reshape(3,4). What does x[:, ::-1] do?

Reverses columns.

37
New cards

Which is the correct way to make a logarithmic x-axis in Matplotlib?

plt.xscale(“log”)

38
New cards

Which of the following is not valid in plt.hist()?

bins = “category”

39
New cards

If plt.subplot(2,2,1) is followed by plt.subplot(2,2,1) again, what happens?

The previous subplot is overwritten.

40
New cards

Which parameter in plt.savefig() can be used to reduce white space around the figure?

bbox_inches = ‘tight’

41
New cards

How to create a 3×3 array with random integers from 0-9?

np.random.randint(10, size(3,3))

42
New cards

If a file is opened with open(‘data.txt’, ‘a’), what happens if the file doesn’t exist?

A new file is created.

43
New cards

Suppose x=np.arange(12).reshape(3,4). What is the result of x[x>5]?

A 1D array

44
New cards

Which Python function is used to determine the data type of a variable?

type()

45
New cards

What is the output of the following code?: 

print(f“{1234,5678:.2f}”)

1234.57

46
New cards

Which of the following is NOT a valid keyword for controlling loops in Python?

stop

47
New cards

Given fruits = {“apple”, “banana”, “cherry”}, what is the correct way to access banana?

fruits[1]

48
New cards

Which of the following will correctly reverse a list mylist?

mylist[::-1]

49
New cards

In Python OOP, which method is called automatically when an object is created?

__init__

50
New cards

What happens if you run:

for i in range(3):

for j in range(3):

if i == j:

break

print(i,j)

Only prints when i > j

51
New cards

Given:

x=”Data”

y=”Science”

print(x+y*2)

What is the output?

DataScienceScience

52
New cards

Which of the following is NOT valid dictionary creation?

dict(1=”a”, 2=”b”)

53
New cards

Which string method would you use to check if a string starts with a particular prefix?

.startswith()

54
New cards

What is the result of:

a=[1,2,3]

b = a

b.append(4)

print(a)

[1,2,3,4]

55
New cards

What is the main advantage of using a tuple over a list?

Tuples are faster and use less memory.

56
New cards

A lambda function in Python can take multiple arguments and contain multiple expressions.

False

57
New cards

The elseif keyword can be used for conditional statements.

False

58
New cards

Tuples in Python allow duplicate values.

True

59
New cards

A list is mutable, whereas a tuple and a set are not.

True

60
New cards

Inherited functions can be modified in subclasses.

True

61
New cards

The statement mylist = [1, 2, 3] * 3 creates the list [1, 2, 3, 1, 2, 3, 1, 2, 3].

True

62
New cards

In a for loop using range(start, end), the end value is inclusive.

True