arrow
arrow
arrow
Select the correct output for the following Python code.for i in range(6, 1, -2):      print(end='*$$')
Question

Select the correct output for the following Python code.
for i in range(6, 1, -2):
      print(end='*$$')

A.

*$$*$$

B.

*$$ *$$ *$$

C.

*$$*$$*$$

D.

*$$ *$$

Correct option is C

Let's break down the given Python code:
for i in range(6, 1, -2):
     print(end='*$$')
· range(6, 1, -2): This generates a sequence of numbers starting from 6, ending before 1, and stepping by -2. So the numbers generated are:
· 6, 4, 2
· print(end='*$$'): The print() function is used to print the string *$$. The end parameter in the print() function specifies what to print at the end of each output. By default, it is a newline (\n), but here, it is set to print *$$ without moving to a new line after each print. As a result, the output will be *$$*$$*$$ printed in a continuous line.
Important Key Points:
1. Range Function: The range(6, 1, -2) generates the numbers 6, 4, 2. The for loop will iterate 3 times.
2. End Parameter in Print: The end parameter of the print() function is used to avoid printing a newline, so the string *$$ is printed three times on the same line.
3. Output: The output will be *$$*$$*$$ because the string *$$ is printed 3 times, each on the same line.
Knowledge Booster:
· Option (b): *$$ *$$ *$$ is incorrect because there is no space between the *$$ strings in the code. The end='*$$' specifies that the strings will be printed consecutively without spaces.
· Option (d): *$$ *$$ is incorrect because there are more than 2 iterations in the for loop, and thus more than two *$$ strings will be printed.

Free Tests

Free
Must Attempt

UPTET Paper 2 Social Science : PYP Held on 23rd Jan 2022 (Shift 2)

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
Free
Must Attempt

UPTET : Paper 1 Full Mock - 01

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
Free
Must Attempt

UPTET : Paper 2 Maths & Science Full Mock - 01

languageIcon English
  • pdpQsnIcon150 Questions
  • pdpsheetsIcon150 Marks
  • timerIcon150 Mins
languageIcon English
test-prime-package

Access ‘EMRS PGT’ Mock Tests with

  • 60000+ Mocks and Previous Year Papers
  • Unlimited Re-Attempts
  • Personalised Report Card
  • 500% Refund on Final Selection
  • Largest Community
students-icon
383k+ students have already unlocked exclusive benefits with Test Prime!
Our Plans
Monthsup-arrow