Informatics Practices
Find the output of the following Python program:
for x in range(1, 20, 3):
print(x, end =',')
- 1,20,3,
- 1,4,7,10,13,16,19,
- 13,6,9,12,15,18,
- 20,40,60,80,100,
Python Control Flow
2 Likes
Answer
1,4,7,10,13,16,19,
Reason — The above code uses a for loop to iterate over a sequence of numbers generated by range(1, 20, 3). This range starts at 1, ends before 20, and increments by 3 in each step. During each iteration, the current value of x is printed followed by a comma due to the end=',' parameter in the print function. Therefore, the output is 1,4,7,10,13,16,19, showing the sequence of numbers separated by commas.
Answered By
2 Likes
Related Questions
What will be the output?
x = ['ab', 'cd'] for i in x: i.upper() print (x)- ['ab', 'cd']
- ['AB', 'CD']
- [None, None]
- None of these
Which statement is used to iterate itself over a range of values or a sequence?
- if
- while
- do-while
- for
if statement comes in which category of statements?
- Sequential statements
- Conditional statements.
- Iterative statements
- Loop statement
Assertion (A): When a set of statements is indented under the same block, starting from the same indentation, it is said to be a compound statement.
Reasoning (R): Compound Statement begins with a header ending with a colon (:) sign and the statements under the same indentation are marked as a block.
- Both A and R are true and R is the correct explanation of A.
- Both A and R are true but R is not the correct explanation of A.
- A is true but R is false.
- A is false but R is true.