Change Value Within Loop but only once

I have a loop I’m running, it’s about 6 different functions joined together, so it’s a little confusing to me but they all seem to be working but this end part.

After the loop is complete it needs to change the answer to a different value depending on the below rules.

I’m quite new to python and programming in general and think I must be missing something. Currently my code appears to be running properly for example if dow was 0 then dow becomes 6 which is correct. But then the elif runs and makes it 5 which breaks everything, help.

if dow == 0:
    dow =6
elif dow == 1:
    dow = 0
elif dow == 2:
    dow = 1
elif dow == 3:
    dow = 2
elif dow == 4:
    dow = 3
elif dow == 5:
    dow = 4
elif dow == 6:
    dow = 5

Upvotes: 1

Views: 832

Answers (2)

big_bad_bison
big_bad_bison

Reputation: 1015

In this situation you can also just replace this loop with:

dow = (dow - 1) % 7

Upvotes: 1

Thank you Deepak Gouda, that fixed it, thank you, so simple. Changed dow to dow1

dow1 = (stdcheck/juniper)%7

if dow1 == 0:
  dow =6
elif dow1 == 1:
  dow = 0
elif dow1 == 2:
  dow = 1
elif dow1 == 3:
  dow = 2
elif dow1 == 4:
  dow = 3
elif dow1 == 5:
  dow = 4
elif dow1 == 6:
  dow = 5

Upvotes: 0

Related Questions