+ 1
'while' and 'for' count corn differently. How can I make both programs count the same?
I wrote two codes based on the legend about the creator of chess. One using 'while' and the other using 'for'. I don’t understand how to make it count correctly with ‘while’ too corn = 1 cell = 64 counter = 1 while counter <= cell: corn *= 2 print('cell ' + str(counter) + ': ' + str(corn)) counter += 1 #and for i in range(64): cell = i+1 corn = 2**i print('cell: ', cell, 'corn' , corn)
4 Respostas
+ 2
In the while loop, corn starts as 1, but gets multiplied before being printed, so it effectively starts as 2. In the for loop, it is created as 1 and then printed.
+ 2
Эдуард Раисович ,
Then print it before you multiply it.
+ 1
where were my eyes?
0
thanks, but I need to know how to implement it in a while loop so that the report starts with 1 cell - 1 corn, 2 cell - 2 corn, 3cell- 4 corn .....