Replacing the for in range loop with while python
Please tell me how to replace the for in range
loop with while
?
def what (a, b):
res = a
for i in range(b):
res = res + 1
return res
0
2 answers
As an option
def what (a, b):
res = a
while b:
res = res + 1
b -= 1
return res
1
Author: S. Nick, 2020-05-05 18:29:32
def what(a, b):
res = a
i = 0
while i < b:
res += 1
i +=1
return res
0
Author: BlueScreen, 2020-05-05 18:28:22