Python Control Structures Quiz 12

Master Python Control Structures with this interactive quiz! This Python Control Structures Quiz is designed for students, programmers, data analysts, and IT professionals. This Python Quiz tests your understanding of if-else, loops (for/while), and flow control in Python. Whether you are a beginner or an expert, sharpen your logic and debugging skills with real-world examples through this Python Control Structures Quiz. Can you score 100%? Let us start with the Online Python Control Structures Quiz now.

Online Python Control Structures Quiz with Answers

Online Python Control Structures Quiz with Answers

1. Considering the function step, when will the following function return a value of 1?

def step(x):
     if x > 0:
         y = 1
     else:
         y = 0
     return y
 
 
 
 

2. What is the result of the following lines of code?

x = 0
while x < 2:
    print(x)
    x = x + 1
 
 
 
 

3. Which loop is best for iterating over a list?

 
 
 
 

4. Which of the following correctly demonstrates the use of an if-else statement to check if a variable ‘x’ is greater than 10 and print ‘High’ if true, or ‘Low’ if false?

 
 
 
 

5. Identify which of the following while loops will correctly execute 5 times.

 
 
 
 

6. What is the output of the following lines of code?

a = 1
def do(x):
    return x + a
print(do(1))
 
 
 
 

7. For the code shared below, what value of $x$ will produce the output “How are you?”?

if(x!=1):
     print('How are you?')
else:
     print('Hi')
 
 
 
 

8. What does the break statement do in a loop?

 
 
 
 

9. What is the output of the following few lines of code?

for i, x in enumerate(['A', 'B', 'C']):
     print(i + 1, x)
 
 
 
 

10. In Python, what is the result of the following code?

x = 0
while x < 3:
      x += 1
print(x)
 
 
 
 

11. Which of the following statements correctly demonstrates the use of an if-else conditional statement in Python?

 
 
 
 

12. What is the output of the following

for x in ['A', 'B', 'C']:
      print(x+'A')
 
 
 
 

13. What will be the result of the following?

for x in range(0, 3):
     print(x)
 
 
 
 

14. What is the output of the following code?

x = "Go"
if x == "Go":
    print('Go')
else:
    print('Stop')
print('Mike')
 
 
 
 

15. What will be the output of the following Python code?

x = 5
y = 10
if x > y:
     print('x is greater than y')
else:
     print('x is less than or equal to y')
 
 
 
 

16. What is the output of the following?

for i in range(1,5):
     if (i!=2):
        print(i)
 
 
 
 

17. Which loop is used when the number of iterations is unknown?

 
 
 
 

18. What result does the following code produce?

def print_function(A):
     for a in A:
         print(a + '1')
 
 
 
 

19. What is the output of the following?

for i, x in enumerate(['A', 'B', 'C']):
     print(i, x)
 
 
 
 

20. Which of the following best describes the purpose of the ‘elif’ statement in a conditional structure?

 
 
 
 

Online Python Control Structures Quiz with Answers

  • Which of the following best describes the purpose of the ‘elif’ statement in a conditional structure?
  • What will be the result of the following?
    for x in range(0, 3):
    print(x)
  • What is the output of the following
    for x in [‘A’, ‘B’, ‘C’]:
    print(x+’A’)
  • What is the output of the following?
    for i, x in enumerate([‘A’, ‘B’, ‘C’]):
    print(i, x)
  • What result does the following code produce?
    def print_function(A):
    for a in A:
    print(a + ‘1’)
  • What is the output of the following code?
    x = “Go”
    if x == “Go”:
    print(‘Go’)
    else:
    print(‘Stop’)
    print(‘Mike’)
  • What is the result of the following lines of code?
    x = 0
    while x < 2:
    print(x)
    x = x + 1
  • What is the output of the following few lines of code?
    for i, x in enumerate([‘A’, ‘B’, ‘C’]):
    print(i + 1, x)
  • Considering the function step, when will the following function return a value of 1?
    def step(x):
    if x > 0:
    y = 1
    else:
    y = 0
    return y
  • What is the output of the following lines of code?
    a = 1
    def do(x):
    return x + a
    print(do(1))
  • For the code shared below, what value of $x$ will produce the output “How are you?”?
    if(x!=1):
    print(‘How are you?’)
    else:
    print(‘Hi’)
  • What is the output of the following?
    for i in range(1,5):
    if (i!=2):
    print(i)
  • In Python, what is the result of the following code?
    x = 0
    while x < 3:
    x += 1
    print(x)
  • What will be the output of the following Python code?
    x = 5
    y = 10
    if x > y:
    print(‘x is greater than y’)
    else:
    print(‘x is less than or equal to y’)
  • Identify which of the following while loops will correctly execute 5 times.
  • Which of the following statements correctly demonstrates the use of an if-else conditional statement in Python?
  • Which of the following correctly demonstrates the use of an if-else statement to check if a variable ‘x’ is greater than 10 and print ‘High’ if true, or ‘Low’ if false?
  • Which loop is used when the number of iterations is unknown?
  • What does the break statement do in a loop?
  • Which loop is best for iterating over a list?

Statistics for Data Analysts and Data Scientists

Python NumPy MCQs 11

These Python NumPy MCQs are designed to test your understanding of fundamental NumPy concepts, including array creation, manipulation, and common operations. The Python NumPy MCQs Quiz consists of multiple-choice questions (MCQs) covering essential topics such as:

  • Array creation (np.array(), np.zeros(), np.arange())
  • Array properties (.shape, .size)
  • Basic operations (dot product, arithmetic)
  • NumPy terminology

Each question is followed by the correct answer, making it useful for self-assessment, interviews, or exam preparation. Whether you are a beginner or an intermediate Python programmer, this Python Quiz helps reinforce key NumPy skills efficiently. Let us start with the Python NumPy MCQs now.

Please go to Python NumPy MCQs 11 to view the test
Online Python NumPy MCQs with Answers

Online Python Numpy MCQs with Answers

  • What result will the following lines of code give?
    a=np.array([0,1])
    b=np.array([1,0]) np.dot(a,b)
  • What does the value of $Z$ become after executing the following code?
    X=np.array([[1,0], [0,1]])
    Y=np.array([[0,1], [1,0]])
    Z=X+Y  
  • If you run the following lines of code, what values will the variable ‘out’ take?
    X=np.array([[1,0,1],[2,2,2]])
    out=X[0:2,2]
  • If you run the following lines of code, what values will the variable ‘out’ take?
    X=np.array([[1,0], [0,1]])
    Y=np.array([[2,2], [2,2]])
    Z=np.dot(X,Y)
  • After executing the given code, what value does $Z$ hold?
    X=np.array([[1,0], [0,1]])
    Y=np.array([[2,1], [1,2]])
    Z=np.dot(X,Y)
  • What outcome do the following lines of code produce?
    a=np.array([0,1,0,1,0])
    b=np.array([1,0,1,0,1])
    a+b
  • What line of code would produce the following: array([11, 11, 11, 11, 11])?
  • Which is the correct way to create a $2\times2$ NumPy array filled with ones?
  • Which of the following are valid ways to create a NumPy array?
  • Which of the following operations can be performed on NumPy arrays?
  • How do you access the element at the second row and third column of a 2D NumPy array ‘arr’?
  • What is the primary purpose of the NumPy library in Python?
  • What Python libraries are commonly used for data mining?
  • What does NumPy stand for?
  • Which of the following statements about creating and manipulating multi-dimensional arrays in Python using NumPy are true?
  • Which function is used to create a NumPy array?
  • What is the output of np.zeros((2,3))?
  • Which method returns the shape of a NumPy array?
  • What does np.arange(5) produce?
  • What does np.random.seed(42) do?

Islamiat MCQs 9th Class Quiz

Python Data Visualization Quiz 10

This Python Data Visualization Quiz focuses on Python’s Matplotlib library, a fundamental tool for data visualization. This Python Quiz tests your understanding of key concepts, functions, and best practices in creating, customizing, and saving plots using Matplotlib. Let us start with the Python Data Visualization Quiz now.

Online Python Data Visualization Quiz with Answers
Please go to Python Data Visualization Quiz 10 to view the test

Online Python Data Visualization Quiz with Answers

  • Which of the following libraries is NOT mentioned as a high-level visualization library?
  • Matplotlib is a widely used Python data visualization library.
  • Which Matplotlib function is used to create histograms?
  • What are some of the key purposes of the Matplotlib library for data visualization?
  • What function in Matplotlib is used to create a basic line plot?
  • Which Matplotlib function would you use to create scatter plots that show the relationship between two arrays?
  • Which of the following are valid ways to create a bar plot in Matplotlib?
  • Which of the following can be created using the Matplotlib library?
  • What is the primary purpose of the Matplotlib library in Python?
  • Matplotlib was created by:
  • What is the code for the Matplotlib magic function?
  • Which two of the following are not examples of Matplotlib magic functions?
  • Which of the following is not a main layer of Matplotlib?
  • Matplotlib was initially developed as what kind of tool?
  • Matplotlib’s three main layers are: Backend, Artist, and Scripting.
  • When plotting directly with Matplotlib, the pyplot module offers a convenient way to create and customize plots quickly.
  • The first step when creating a histogram in matplotlib is to import matplotlib as ———— and its scripting interface as ————–.
  • What is the process of creating a scatter plot?
  • The Python library we used to plot the graphs is ————–.
  • How do you create a scatter plot in Matplotlib?

Statistics and Data Analysis