开发者

How to prevent first print function interrupting second for loop? [closed]

开发者 https://www.devze.com 2022-12-07 17:27 出处:网络
Closed. This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and开发者_运维技巧 clarify the problem by editing this pos
Closed. This question needs details or clarity. It is not currently accepting answers.

Want to improve this question? Add details and开发者_运维技巧 clarify the problem by editing this post.

Closed 45 mins ago.

Improve this question
direction = input("Type 'encode' to encrypt, type 'decode' to decrypt:\n")
text = input("Type your message:\n").lower()
shift = int(input("Type the shift number:\n"))

def caesar(plain_text, shift_amount, direction_d):
  cipher_text = ""
  for letter in plain_text:
    position = alphabet.index(letter)
    if direction_d == "encode" :
      new_position = position + shift_amount
      cipher_text += alphabet[new_position]
      print(f"The encoded text is {cipher_text}")
    if direction == "decode":
      new_position = position - shift_amount
      cipher_text += alphabet[new_position]
  print(f"The encoded text is {cipher_text}")

caesar(plain_text = text , shift_amount = shift, direction_d = direction)

I want to print last line of the first if statement but if I exit for loop (to do that) it will interrupt the second loop which i've already exited loop and I can print the last line of loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消