Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # https://stackoverflow.com/questions/57651384/how-to-fix-infinite-printing-on-while-statement
- # As I said in comment you forgot `x = x + 1` when you display `" "` so it never move to next char in message
- # and it check again and again the same char which is converted to `" "`
- import string
- letras = list(string.ascii_lowercase)
- message = input("qual sua menssagem codificada?")
- cod = input("qual a numeração da cifra?")
- meslist = list(message)
- trans = True
- num = len(meslist)
- x = 0
- while trans:
- if num > x:
- if meslist[x] in letras:
- a = letras.index(meslist[x])
- print(letras[a + 2])
- x = x + 1
- trans = True
- else:
- print(" ")
- x = x + 1 # <---
- trans = True
- elif num == 0:
- trans = False
- # But you could write it with `for` loop and then you don't need `x` and `trans`
- # You also forget that sometimes `letras[a + 2]` may give error `IndexError: list index out of range`
- # and then in `caesar cipher` you have to move to beginning `letras[ a+2-len(letras) ]`
- # (or alwasy take modulo `letras[ a+2 % len(letras) ]`)
- import string
- letters = string.ascii_lowercase
- message = input("message: ")
- code = int(input("number: "))
- for char in message:
- if char in letters:
- position = letters.index(char)
- position += code # position += 2
- if position > len(letters):
- position -= len(letters)
- print(letters[position], end='') # don't go to new line
- else:
- print(" ", end='') # don't go to new line
- print() # go to new line
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement