0

I need to keep looping this cipher until the input is blank. Please help. TIA

c = input(str())
encrypted = str()
key = 5

for c in c:
    if c.isupper():
        c_unicode = ord(c)
        c_index = ord(c) - ord("A")
        new_index = (c_index + key) % 26
        new_unicode = new_index + ord("A")
        new_character = chr(new_unicode)
        encrypted = encrypted + new_character
    print(encrypted)
    print()
  • Can you give a more detailed description of what exactly is wrong with this code? It looks like this would run perfectly to me. – Cmd858 Nov 19 '21 at 13:36
  • You can compare the value in `c` with the characters you think are "blank", then use `break` to get out of the loop. Don't reuse variables like you did in `for c in c`, that's really not best practice. – Maarten Bodewes Nov 19 '21 at 15:05
  • @CmdCoder858 hi, I need to put this loop inside a loop wherein the code will ask for input from the user UNTIL the user enters a blank entry, then the program will stop running. – SEA_mnft Nov 20 '21 at 00:19
  • @MaartenBodewes thank you for your answer. May I know how can I improve the got? I really got stuck on how can I program it to keep asking the input until the user inputs a blank entry. – SEA_mnft Nov 20 '21 at 00:20
  • Oh, like that. You can just get the answer [here](https://stackoverflow.com/a/20511221/589259). Just focus on the `line` specific parts and the `while line` statement. – Maarten Bodewes Nov 20 '21 at 00:52
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Nov 22 '21 at 18:39

0 Answers0