CT-3 QB

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

Which type of files does Google Colab support for importing code?

a) .ipynb b) .txt c) .cpp d) .exe


What does len("Python") return?
a) 5 b) 6 c) 7 d) Error
Find the symbol is used for single-line comments in Python.
a) // b) # c) /* */ d) <!-- -->
What is the correct syntax for an if statement?
a) if condition {} b) if (condition):
c) if condition: d) if: condition
How do you append an element to a list?
a) list.append() b) list.add()
c) list.insert() d) list.push()
How do you access the first element of a tuple t = (10, 20, 30)?
a) t[1] b) t.first() c) t[0] d) t.get(1)
How is variance calculated in NumPy?
a) np.var() b) np.variance()
c) np.std() d) np.average()
What is the correct method to create a DataFrame in Pandas?
a) pd.Series()
b) pd.DataFrame()
c) pd.Panel()
d) pd.Index()
Which method is used to sort a DataFrame by column values?
a) df.sort_columns() b) df.order_by()
c) df.sort_values() d) df.sort()
Which is faster for numerical operations?
a) NumPy b) Pandas
c) Both are equally fast d) Neither of them
What is the primary purpose of the Scikit-learn library?
a) Data manipulation b) Machine learning
c) Data visualization d) Statistical modelling
What is the correct extension for Python files?
a) .py b) .pyt c) .python d) .txt
What is the default data type of 5 in Python?
a) int b) float c) double d) bool
Which Python keyword is used for an alternative condition?
a) elseif b) elif c) else if d) end if
How many times does the following loop run?
for i in range(5):
print(i)
a) 4 b) 5 c) Infinite d) Error
What does list1[1:3] return for list1 = [10, 20, 30, 40]?
a) [10, 20, 30] b) [20, 30] c) [30, 40] d) Error
What is a key-value pair?
a) Item and index b) Dictionary element
c) Key and value stored in a dictionary
d) None of the above
What will the command np.zeros((2, 3)) create?
a) A 2x3 array of ones b) A 2x3 array of zeros
c) A 3x2 array of zeros d) A 2x2 array of zeros
Which function calculates the percentile of an array?
a) np.median() b) np.percentile()
c) np.mode() d) np.average()
Which of the following is the correct syntax for creating a NumPy array in
Python?
a) np.array([1, 2, 3]) b) numpy.array([1, 2, 3])
c) array([1, 2, 3]) d) array([1, 2, 3], dtype=int)
Which of the following is the correct way to slice a NumPy array arr to get the
first 3 elements?
a) arr[3:] b) arr[:3] c) arr[1:3] d) arr[0:3]
What is the primary purpose of the Scikit-learn library?
a) Data manipulation b) Machine learning
c) Data visualization d) Statistical modelling

Python is a __________ programming language.


a) compiled b) interpreted c) assembly-level d) machine-level

What is the correct extension for Python files?


a) .py b) .pyt c) .python d) .txt
Which company developed Google Colab?
a) Microsoft b) Google c) Amazon d) Facebook
Which type of files does Google Colab support for importing code?
a) .ipynb b) .txt c) .cpp d) .exe
What is the default data type of 5 in Python?
a) int b) float c) double d) bool
What will the following return: type(3.14)?
a) int b) float c) double d) None
Which of the following is a Boolean type?
a) True b) false c) 0 d) 1.0
What does len("Python") return?
a) 5 b) 6 c) 7 d) Error
Which function converts a string to uppercase?
a) str.upper() b) string.uppercase() c) upper() d)
toUpper()
How do you take user input in Python?
a) input() b) read() c) scanf() d) getInput()
What function is used to display output in Python?
a) display() b) print() c) cout() d) log()
What symbol is used for single-line comments in Python?
a) // b) # c) /* */ d) <!-- -->
Which keyword is used for handling exceptions in Python?
a) catch b) except c) handle d) error
What is the correct syntax for an if statement?
a) if condition {} b) if (condition): c) if condition: d) if:
condition
Which Python keyword is used for an alternative condition?
a) elseif b) elif c) else if d) end if
How many times does the following loop run?
for i in range(5):
print(i)
a) 4 b) 5 c) Infinite d) Error
Which loop runs indefinitely?
a) for b) while True c) do-while d) until
How do you append an element to a list?
a) list.append() b) list.add() c) list.insert() d) list.push()
What does list1[1:3] return for list1 = [10, 20, 30, 40]?
a) [10, 20, 30] b) [20, 30] c) [30, 40] d) Error

How do you access the first element of a tuple t = (10, 20, 30)?
a) t[1] b) t.first() c) t[0] d) t.get(1)

Which operation removes duplicates from a list?


a) list(set()) b) removeDuplicates() c) distinct() d)
set(list())
What will set1.union(set2) do?
a) Intersection
b) Combine elements from both sets without duplicates
c) Modify set1 only d) Modify set2 only
What is a key-value pair?
a) Item and index b) Dictionary element
c) Key and value stored in a dictionary d) None of the above
How do you access a value in a dictionary?
a) dict.key() b) dict[key]
c) dict.get() d) Both b and c
Which library is used for numerical computations?
a) Pandas b) NumPy
c) Matplotlib d) SciPy
Which library is best for data visualization?
a) NumPy b) Matplotlib c) TensorFlow d) Pandas
How do you create a NumPy array?
a) np.array() b) numpy.array() c) Both a and b d) array()
What is the function to calculate the mean of a NumPy array?
a) mean() b) np.mean() c) avg() d) np.avg()
How do you create a 2D array in NumPy?
a) np.array([[], []])
b) np.create2D()
c) Both a and b
d) None of the above
Answer: a) np.array([[], []])

What does array.shape return?


a) Number of elements in the array
b) Dimensions of the array
c) Data type of array elements
d) None of the above
Answer: b) Dimensions of the array

16. Error Handling


Which keyword is used to raise an exception?
a) throw
b) raise
c) except
d) error
Answer: b) raise

What does the finally block do?


a) Executes only if there is no exception
b) Executes regardless of whether an exception occurs or not
c) Executes before the try block
d) None of the above
Answer: b) Executes regardless of whether an exception occurs or not
If you need more questions, let me know!

You said:
need more
ChatGPT said:
ChatGPT
Here are more MCQs on the remaining topics to meet your requirements:

17. Python - Input and Output Functions


What will the following code output?
python
Copy code
name = input("Enter your name: ")
print(f"Hello, {name}!")
a) Syntax Error
b) Runtime Error
c) Displays the entered name
d) None of the above
Answer: c) Displays the entered name

Which method reads input as an integer directly?


a) input()
b) read_int()
c) int(input())
d) None of the above
Answer: c) int(input())
18. Python - Looping Statements
What is the output of the following code?
for i in range(3):
print(i, end=" ")
a) 0 1 2
b) 1 2 3
c) 0 1 2 3
d) Syntax Error
Answer: a) 0 1 2

What does the break statement do?


a) Exits the loop and terminates the program
b) Skips the current iteration
c) Terminates the loop entirely
d) None of the above
Answer: c) Terminates the loop entirely

Which statement is used to skip an iteration in Python?


a) skip
b) continue
c) pass
d) break
Answer: b) continue

What does the following code do?


python
Copy code
my_list = [10, 20, 30]
my_list.append(40)
print(my_list)
a) [10, 20, 30]
b) [10, 20, 30, 40]
c) [10, 40]
d) None of the above
Answer: b) [10, 20, 30, 40]

What is the correct syntax to remove an element from a list by value?


a) list.pop(value)
b) list.remove(value)
c) list.delete(value)
d) del list[value]
Answer: b) list.remove(value)

What will the following code output?


list1 = [1, 2, 3, 4]
print(list1[1:3])
a) [1, 2, 3]
b) [2, 3]
c) [2, 3, 4]
d) Error
Answer: b) [2, 3]

What will dict1 = {'a': 10, 'b': 20} return for dict1['a']?
a) 10
b) 'a'
c) Error
d) None
Answer: a) 10

Which method is used to get all the keys in a dictionary?


a) keys()
b) getKeys()
c) allKeys()
d) dict_keys()
Answer: a) keys()

Which library is best suited for working with structured data (tables)?
a) NumPy
b) Pandas
c) Scikit-learn
d) TensorFlow
Answer: b) Pandas

Which Python library is primarily used for machine learning?


a) Scikit-learn
b) Matplotlib
c) NumPy
d) Pandas
Answer: a) Scikit-learn

Which of the following creates a 1D array of zeros?


a) np.zeros((3,))
b) np.zeros([1, 2])
c) np.zeros(3)
d) None of the above
Answer: c) np.zeros(3)

What does np.arange(0, 5, 2) return?


a) [0, 2, 4]
b) [1, 2, 3, 4]
c) [0, 2]
d) [2, 4, 6]
Answer: a) [0, 2, 4]

What will the following code output?


arr = np.array([[1, 2], [3, 4]])
print(arr[1, 0])
a) 1
b) 3
c) 4
d) Error
Answer: b) 3

What does array.ndim return?


a) Shape of the array
b) Number of dimensions
c) Number of elements
d) Data type
Answer: b) Number of dimensions

What does np.var(array) compute?


a) Mean
b) Variance
c) Standard deviation
d) Percentile
Answer: b) Variance

What will np.percentile([1, 2, 3, 4], 50) return?


a) 2
b) 2.5
c) 3
d) 4
Answer: b) 2.5

Which method creates a DataFrame in Pandas?


a) pd.DataFrame()
b) pd.createDF()
c) df.create()
d) pd.DataFrame.create()
Answer: a) pd.DataFrame()

What does the head() function in Pandas do?


a) Shows the last few rows of the DataFrame
b) Shows the first few rows of the DataFrame
c) Summarizes the DataFrame
d) Deletes columns
Answer: b) Shows the first few rows of the DataFrame

How do you query a DataFrame for rows where a column is greater than a value?
a) df.column > value
b) df[df['column'] > value]
c) df.query(column > value)
d) None of the above
Answer: b) df[df['column'] > value]

What is the output of the following code?


df = pd.DataFrame({'A': [10, 20, 30], 'B': [40, 50, 60]})
print(df.loc[1, 'B'])
a) 50
b) 60
c) 40
d) Error
Answer: a) 50

1) Write about Python, and why is it widely used in fields such as data
science and web development? List its key features.
2) Write a program to accept a list of numbers from the user. Sort the list into
ascending order and remove any duplicates.
3) Differentiate list from tuples with appropriate examples.
4) Brief the key attributes of a NumPy array? Explain the purpose of ndim,
shape, and dtype.
5) You have a DataFrame representing student grades. Write a function to
classify students as "Pass" or "Fail" based on their grades and apply it to
the DataFrame.
6) Explain the differences between a Pandas Series and a Pandas DataFrame.
Provide examples of when each would be used.
7) Describe the concept of sets in Python. How do you create and manipulate
sets, and what makes them different from lists and tuples?
8) Discuss the key differences between NumPy and Pandas, focusing on their
structures, functionalities, and performance. Include the following aspects
in your answer:
(i)Describe the fundamental concepts behind NumPy and Pandas libraries
in Python.
(ii)Explain the process of creating a NumPy array and a Pandas DataFrame.
Provide examples of syntax.
(iii)Provide examples of slicing in both libraries and explain when each
method is preferred.
(iv) Discuss the speed performance of NumPy and Pandas in handling
large datasets.
9) Explain the differences between a WHILE loop and a FOR loop in python.
When would you choose one over the other?
10) Write a Python program to find the union, intersection, and
difference between two sets of student names.
11) Brief dictionary and it’s any 5 operations with examples.
12) What is a percentile? How can it be calculated using NumPy’s
percentile() function?
13) How does slicing in NumPy differ from slicing in Python lists? Explain
with examples.
14) Create a DataFrame to represent sales data for a store (Product
Name, Quantity, Price). Display the first five rows of the DataFrame.
15) Compare the following Python data structures: Set, List, Tuple, and
Dictionary. Your answer should include:
16) 1.Definition and a brief description of each data structure.
17) 2.At least two unique features of each data structure with example.
• Adding elements (if applicable).
• Accessing elements (if applicable).
18) Explain some popular Python libraries for data analysis and
visualization. Describe their use cases briefly.

You might also like