Post

Python Programming
Python Programming@PythonPr·
Python Question / Quiz; What is the output of the following Python code, and why? Comment your answers below!
Python Programming tweet media
English
34
10
115
10.8K
Earnest Codes
Earnest Codes@Earnesto037·
@PythonPr Answer: B) 1 3 The Python code uses the range(start, stop, step) function. start is 1 (inclusive). stop is 5 (exclusive). step is 2. The loop starts at (i=1). The next value of (i) is (1+2=3). The next value would be (3+2=5), but this is equal to the stop value, so the loop
English
1
0
10
571
Python Tech
Python Tech@PythonTech43716·
@PythonPr B 13 is the right answer Simple use of for loop and range function (start,end,stepsize) here stepsize is given 2 and by default is 1 end is excluded and start is included here so output will be 1, 1+2 = 3 3+2 = 5 but end is excluded so we answer will be 1 3.
English
0
1
2
501
Jenny
Jenny@JennyTheDev·
@PythonPr B) 1 3 range(1, 5, 2) → starts at 1, stops before 5, step 2 So: 1, 3 The third parameter is the sneaky one that trips everyone up.
English
0
0
3
572
ANKIT 𓃱
ANKIT 𓃱@A9kitSingh·
@PythonPr B) 1 3 range(1, 5, 2) starts at 1, increments by 2, and stops before 5 → 1, 3.
English
0
0
2
402
Jay
Jay@learnaiwthme·
@PythonPr The correct answer is B) 1 3. range(1, 5, 2) starts at 1, stops before 5, and steps by 2. So it produces: 1, 3. With end=" ", they print on the same line: 1 3
English
0
0
1
599
Mohamed Ibrahim
Mohamed Ibrahim@MahmmedIbr88346·
@PythonPr B) Because it's a loop from 1 to 5, and it moves two steps in between, so we'll take 1 and 3.
English
0
0
1
116
Evil_Hunter
Evil_Hunter@imsmartVik·
@PythonPr b is correct option start stop step 1 3 on 5 its terminates
English
0
0
1
85
Harish
Harish@tweet_harry00·
@PythonPr B Range Start from 1 (inclusive) End at 5 (exclusive), so 4 is the max range Step size 2 1 prints 1 + 2 (step size) - 3 prints 3 + 2 (step size) - 5 out of range
English
0
0
1
228
Jimmy Fikes
Jimmy Fikes@akajim·
@PythonPr B. Start with 1. Skip 2 is 3. Must stop before 5. So, 1 3
English
0
0
0
55
Ehshanulla
Ehshanulla@Ehshanulla·
@PythonPr How range(1, 5, 2) works Start at 1 Stop before 5 Step by 2 So the values of i are: 1 3
English
0
0
0
25
Ahmed
Ahmed@AhmA45695305·
@PythonPr First fix the indentation error
English
0
0
0
23
Paylaş