How can I loop among certain numbers even if they are added or subtracted? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How can I loop among certain numbers even if they are added or subtracted?

For example: the limit of my number_list is 6. now if I add 5 to 3, the answer shouldn't be 8, but instead, it should be 1. 5 should be added in this way to three; 3 (add 1)= 4(add 1) = 5(add 1)= 6 (add 1) = 0(add 1) = 1

26th Feb 2018, 6:32 PM
Prashant Pant
Prashant Pant - avatar
3 Answers
+ 8
x=3 for i in range(5): x= (x+1)%7 print(x)
26th Feb 2018, 6:42 PM
Oma Falk
Oma Falk - avatar
+ 2
a = int(input("number to add")) x = 1 if x + a > 6: x = 1 print(x) else: x = x + a print(x) change x to 0 if u want lowest to be 0
26th Feb 2018, 7:09 PM
Markus Kaleton
Markus Kaleton - avatar
26th Feb 2018, 10:19 PM
Sebastian Keßler
Sebastian Keßler - avatar