+ 5

The subraction game is played as follows:

There is list of 'n' numbers.Tke all pairs consecutive num in the list & tke their difference.if the difference is +ve ,replace the element in list by the +ve num.else that element is unchange (last num in the list remains unchanged).The new values form the new list.game is played again & again till there will be no further change in the list. example:n=5, list:[34,56,20,90,100] round1:[34,36,20,90,100] round2:[34,16,20,90,100] round3:[18,16,20,90,100] round 4:[2,16,20,90,100] write python code for this??

2nd Oct 2017, 3:53 AM
sadiya zainab
sadiya zainab - avatar
5 Answers
2nd Oct 2017, 5:10 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 5
Thank you @kartikey
2nd Oct 2017, 5:22 AM
sadiya zainab
sadiya zainab - avatar
+ 5
@kartikey In your code,where it is checking for -ve number??
2nd Oct 2017, 5:26 AM
sadiya zainab
sadiya zainab - avatar
+ 1
@Zainab My Pleasure
2nd Oct 2017, 5:23 AM
Kartikey Sahu
Kartikey Sahu - avatar
+ 1
l[i+1] < l[i]: This checks if the current number is greater than next number Hence, no need to check if difference is +ve or -ve, this makes the code shorter 🙂
2nd Oct 2017, 5:27 AM
Kartikey Sahu
Kartikey Sahu - avatar