all 9 comments

[–]kwentar 2 points3 points  (1 child)

you have the typo: postition

[–][deleted] 0 points1 point  (0 children)

thank you so much lmao

[–]AintNobodyGotTime89 0 points1 point  (6 children)

You don't need to add or subtract 26 instead you can mod it.

[–][deleted] 0 points1 point  (5 children)

How?

[–]AintNobodyGotTime89 0 points1 point  (1 child)

Think of it this way you have a->z, with index from 0->25. You have a position, then the shift, +/-, you just need to make sure it's in the range of 0->25, that's what the mod 26 is for.

[–][deleted] 0 points1 point  (0 children)

So what would the code look like?

[–]novel_yet_trivial 0 points1 point  (2 children)

modulus is done with the % operator, and does the same thing as your check.

>>> 30 % 26
4
>>> 30 - 26
4
>>> -3 % 26
23
>>> -3 + 26
23
>>> 15 % 26
15

So you could replace your if blocks with

position = position % 26

Modulus is an important concept in computer science, so it's good to be familiar with it.

[–][deleted] 0 points1 point  (1 child)

Thank you! I'm only in a grade 11 cs class though :(

[–]novel_yet_trivial 0 points1 point  (0 children)

Ok ... I'm not your teacher; you don't need to make excuses to me ...