Code -
j = 1
while j <= 2 :
print(j)
j++
Explanation -
It looks like there's a small syntax error in your code. In Python, the increment operator is +=, not ++. Here's the corrected version:
j = 1
while j <= 2:
print(j)
j += 1
This code initializes the variable j with the value 1 and then enters a while loop. The loop continues as long as j is less than or equal to 2. Inside the loop, the current value of j is printed, and then j is incremented by 1 using j += 1.
When you run this corrected code, the output will be:
1
2
Each number is printed on a new line because the print function automatically adds a newline character by default.
0 Comments:
Post a Comment