0

how can I print "\n" as a normal newLine "\n"

example:

str = "lorem\\nipsum"

the output should be:

lorem
ipsum

not : lorem\\nipsum

I tried :

print(str[6:])

and more stuff but nothing work

#THE IDEA IS TO GET RAID OF ONLY ONE BACKSLASH TO PRINT IT AS NEWLINE CHARACTER AS SHOULD

ord("\x1c")

>>28

mystr = "\\x1c"

ord(mystr[1:])

  File "<stdin>", line 1, in <module>
TypeError: ord() expected a character, but string of length 3 found```



## here's the actual code ##

import string

lower = list(string.ascii_lowercase) lower_dec = []

upper = list(string.ascii_uppercase) upper_dec = []

nums = list(map(str,range(0,10))) nums_dec =[]

def E(key,p):

cipherList = []
cipherText = []
for row in range(len(key)):
    c = 0
    for i in range(len(key[row])):
        c+= (ord(p[i])*key[row][i])%26
    cipherList.append(repr(chr(c)))


for char in cipherList:
    cipherText.append(char.replace("'",''))


return cipherText

key = [[2,3,5],[11,4,7],[20,12,12]] p = ['p','a','y']

print(E(key,p))

#that prints ['\x1c', '1', '.']

at_Root
  • 71
  • 5

1 Answers1

1

In python you can just do:

print("lorem\nipsum")

This will print:

lorem
ipsum

Python will automatically recognize that as an escape character. For the full list of escape characters please have a look at this.

Josip Domazet
  • 2,246
  • 2
  • 14
  • 37
  • If you want keep the `\\n` you could do `print(str.replace("\\n", "\n"))` to have the desired output but I do not understand why you want that. – Josip Domazet Dec 18 '21 at 21:47
  • I'm training on cyphir algorith that when the algorithm change the char value ,it might give an escape character like the decimal value value 28 wich is "\x1c" – at_Root Dec 18 '21 at 21:59
  • here is the code import string lower = list(string.ascii_lowercase) lower_dec = [] upper = list(string.ascii_uppercase) upper_dec = [] nums = list(map(str,range(0,10))) nums_dec =[] def E(key,p): cipherList = [] cipherText = [] for row in range(len(key)): c = 0 for i in range(len(key[row])): c+= (ord(p[i])*key[row][i])%26 cipherList.append(repr(chr(c))) for char in cipherList: cipherText.append(char.replace("'",'')) return cipherText key = [[2,3,5],[11,4,7],[20,12,12]] p = ['p','a','y'] print(E(key,p)) – at_Root Dec 18 '21 at 22:01
  • This is something that belongs in your original question. Please edit that. But u can just replace that escape character (whatever it may be) with "\n" for the print statement. – Josip Domazet Dec 18 '21 at 22:03
  • it looks easy to solve but actually I do the search but nothing help .. I mean any where – at_Root Dec 18 '21 at 22:03