-1

I created a small program using the ASCII table. I am encrypting the string the user inputs. What I'm confused about is the "\" is its division? Or what is it separating?

plainText = input("Enter a one-word, lowercase message: ")
distance = int(input("Enter the distance value: "))
code = ""
for ch in plainText:
    ordValue = ord(ch)
    print(1, ordValue)
    print(2, ch)
    cipherValue = ordValue + distance
    print(3, cipherValue)
    if cipherValue > ord('z'):
#                                    what does "\" stand for 
        cipherValue = ord('a') + distance - \
                      (ord('z') - ordValue + 1)
        print(4, cipherValue)
    code += chr(cipherValue)
    print(5, code)
ds007
  • 27
  • 2
  • 9

2 Answers2

1

\ escapes the newline. That means that if the line is an expression, it tells the parser to use the next line as part of the same line.

So

x + 2 + \
  3

is the same as x + 2 + 3.

This is especially helpful with a bunch of repeated method calls, like:

my_object \
  .method_a() \
  .method_b(c) \
  .method_d(e=f) \
  .method_g()

which can sometimes be more readable than my_object.method_a().method_b(c).method_d(e=f).method_g()

More about this behavior can be found in the Python language reference.

Edward Minnix
  • 2,699
  • 1
  • 11
  • 26
0

Forward slash is division [ / ]. You're using backslash [ \ ] which is the escape character for python. If you use it alone at the end of the line, it merges the line the slash is on and the next line into one statement. Like this

Ben Adams
  • 119
  • 2
  • 11