Python Loop and Control Statements Quiz
42 Questions
1 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What is the value of 'i' when the loop begins execution?

  • 3
  • 2
  • 1 (correct)
  • 0
  • What will happen during the first iteration of the loop?

  • The loop will terminate immediately. (correct)
  • The value of i will be incremented by 1.
  • The loop will execute without entering the if statement.
  • The code will print the value of i.
  • Which of the following statements is true regarding the if statement within the loop?

  • The if statement never gets executed. (correct)
  • The if statement will always evaluate to true.
  • The if statement causes an infinite loop.
  • The if statement will only execute if i is odd.
  • What will be printed by the code?

    <p>No output</p> Signup and view all the answers

    What is the purpose of the 'break' statement in the code?

    <p>To exit the loop if the condition is not met.</p> Signup and view all the answers

    What will be the output of the first code snippet that initializes A and iterates through a range of 4?

    <p>1</p> Signup and view all the answers

    In the first code snippet, what will the value of A be after the loop finishes execution?

    <p>2</p> Signup and view all the answers

    What will be printed by the second code snippet that uses a while loop with count?

    <p>0 3 6 9 12 15</p> Signup and view all the answers

    For the given boolean expressions in the third code snippet, what will be printed?

    <p>c</p> Signup and view all the answers

    In the third code snippet, which conditions evaluate to false for the print statements?

    <p>all conditions evaluate to true</p> Signup and view all the answers

    What will be the output of the following program on execution: print('''tom ... harry''')?

    <p>tom sam harry</p> Signup and view all the answers

    What will be the output of the command: print(print(print('python')))?

    <p>None</p> Signup and view all the answers

    Which operator is used for exponentiation in Python?

    <p>**</p> Signup and view all the answers

    What is the result of the expression 34 % 3?

    <p>1</p> Signup and view all the answers

    What happens when you attempt to execute: print('tom sam harry')?

    <p>Outputs with line breaks as shown</p> Signup and view all the answers

    What is the erroneous output for the command: print(”’tomsamharry”’)?

    <p>Error: Invalid quotes</p> Signup and view all the answers

    What is the output of the following code: print('this is a number:', 42)?

    <p>this is a number: 42</p> Signup and view all the answers

    Which of the following Python print statements causes an error?

    <p>print(‘tomsam’)</p> Signup and view all the answers

    What will be the output of the code when the 'play' method is called from the Son class?

    <p>Child class</p> Signup and view all the answers

    Why does the code not raise an error when an instance of Son is created and its 'play' method is invoked?

    <p>The Son class implements all abstract methods.</p> Signup and view all the answers

    What will be the result if arr2 is incorrectly defined in the given NumPy code?

    <p>The code will produce a concatenation error.</p> Signup and view all the answers

    What is the purpose of the np.concatenate function in the provided code?

    <p>To merge two arrays into one.</p> Signup and view all the answers

    What will be the shape of the array after the concatenation if arr2 is defined as np.array([[9]])?

    <p>(3, 3)</p> Signup and view all the answers

    What type of class is Father in the provided code example?

    <p>Abstract class</p> Signup and view all the answers

    How many total methods are defined in the Father class?

    <p>2</p> Signup and view all the answers

    If the statement 'print(arr)' is executed and arr is formed by concatenating valid arrays, what will it output?

    <p>A 2-dimensional array.</p> Signup and view all the answers

    What is the output of the following code? x=2; for i in range(x): x -= 2; print(x)

    <p>-2</p> Signup and view all the answers

    In which type of loop can the continue statement be utilized?

    <p>all types of loops</p> Signup and view all the answers

    What will be the output of the following code? int("Enter value of x:")

    <p>Error</p> Signup and view all the answers

    What is the output of the following code? for i in range[0, 10]: print("They are equal"); else: print("They are unequal")

    <p>SyntaxError</p> Signup and view all the answers

    What will the output of the following code be? a=5; b=5.0; print('yes') if (a==b) else 'no'

    <p>yes</p> Signup and view all the answers

    What is the likely result of attempting to execute the following Python code block? int("Enter value of x:")

    <p>ValueError raised</p> Signup and view all the answers

    How does the print statement behave in this code? for i in range(0, 10): print("They are equal")

    <p>Prints 'They are equal' ten times</p> Signup and view all the answers

    Which of these statements is true regarding the use of float and integer comparisons?

    <p>An integer can be equal to a float if they have the same value</p> Signup and view all the answers

    What will be the output of the following code: x = np.where(arr%2 == 1) where arr is defined as np.array([1, 2, 3, 4, 5, 6, 7, 8])?

    <p>array([0, 2, 4, 6])</p> Signup and view all the answers

    What is the output of the following code snippet? print(arr[0,1],arr[1,1]) where arr is defined as np.array([[1,2,3,4,5], [6,7,8,9,10]])?

    <p>18</p> Signup and view all the answers

    What will this code output? obj = der() followed by print(obj.x, obj.y) if der inherits from A and has its own constructor?

    <p>5 3</p> Signup and view all the answers

    Considering the class structure, what is the purpose of super().__init__() in class der?

    <p>To initialize an instance of class <code>A</code></p> Signup and view all the answers

    What will the code block print(x) output after executing x = np.where(arr%2 == 1)?

    <p>tuple with arrays of indices</p> Signup and view all the answers

    In the given code, what will happen if y is not provided when creating an object of class der?

    <p>It will default <code>y</code> to 3, as per the constructor</p> Signup and view all the answers

    Which of the following statements is correct about the array arr defined as np.array([1, 2, 3, 4, 5, 6, 7, 8])?

    <p>It has a dimension of 1 and a shape of (8,).</p> Signup and view all the answers

    What will be the output if the following code is run: arr = np.array([[1,2],[3,4]]); print(arr[0][1])?

    <p>2</p> Signup and view all the answers

    Study Notes

    No Topic Provided

    • No information was given to generate study notes. Please provide the text or questions.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    PB_Python-I_SEM III_2024 PDF

    Description

    Test your understanding of Python loops and control statements with this engaging quiz. Questions cover various aspects including the 'for' loop, 'while' loop, 'if' statements, and more. Perfect for learners who wish to solidify their Python coding skills.

    More Like This

    Untitled
    10 questions

    Untitled

    SmoothestChalcedony avatar
    SmoothestChalcedony
    Quiz de programmation Python
    10 questions

    Quiz de programmation Python

    ComprehensiveDiscernment avatar
    ComprehensiveDiscernment
    Python Loops and Control Structures
    5 questions
    Use Quizgecko on...
    Browser
    Browser