Robotics & Artificial Intelligence
Assertion (A): Loop is a repetitive structure in which a statement or a set of statements are executed until the desired number of iterations is over.
Reason (R): The for loop is used to repeat the execution of a block of statements for a fixed number of times.
Based on the above assertion and reasoning, pick an appropriate statement from the options given below:
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true and R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
- Both A and R are false.
Python Control Flow
1 Like
Answer
Both A and R are true and R is not the correct explanation of A.
Reason — A loop is a repetitive structure used to execute statements repeatedly until the required number of iterations are over. The for loop is one type of loop that is used when the number of iterations is fixed. Therefore, both statements are true, but the second statement does not explain the first statement.
Answered By
2 Likes
Related Questions
Predict the output of the following snippet:
for i in range(4): for j in range(i, -1, -1): print(j, end=' ') print()Predict the output of the following snippet:
for x in range(1, 4): for y in range(1, 3): print(x*y, end=' ') print()Assertion (A): The range() function is a built-in function which is used with the for loop.
Reason (R): This function doesn't require any parameter. It is used in for loop to generate the series such as even and odd numbers, positive and negative numbers, etc.
Based on the above assertion and reasoning, pick an appropriate statement from the options given below:
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true and R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.
- Both A and R are false.
A Python program that takes a list of integers and tests the user's ability to:
- write a code in Python.
- use for loops for iteration to iterate over a list.
- apply conditional statements to check divisibility.
- print the results based on the condition.
A list of integers [10, 15, 24, 30, 20, 45, 25, 60] is provided.
The program counts and prints all numbers from the list that are divisible by 3 as well as 5.
The expected output:
The numbers divisible by 3 as well as 5 in the list are: 15 30 45 60 Number of elements divisible by 3 as well as 5: 4An outline of the program is given below to make the task easier.
Now, fill in the blanks to complete the code. The program is given below:
# a program to display numbers divisible by 3 and 5 in the list c = 0 My_List = [10, 15, 24, 30, 20, 45, 25, 60] print("Given List:", My_List) print("The numbers divisible by 3 as well as 5 in the list are:") for ........... in My_List: # line 1 if(num%3 == 0 ......... num%5 == 0): # line 2 print(num) c = ............... # line 3 print("Number of elements divisible by 3 as well as 5: ", c)