Python Forum
Help with function - encryption - messages - NameError: name 'message' is not defined
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with function - encryption - messages - NameError: name 'message' is not defined
#5
(Nov-11-2022, 07:42 PM)MrKnd94 Wrote: [Yes, I do know that neither
Quote:message
or maybe
Quote:shift
hasn't been defined. How can I fix it please?
By defining them?

The errors are in
encrypt(message, shift)
and
decrypt(message,shift)
For encrypting the message, how is your program supposed to accept input? Does the user type in a message? Are there test messages you are supposed to encrypt? Any of these would work:
encrypt(input("Enter message: ", 8)
encrypt("This is the message", 5)
message = "This is the message"
shift = 9
encrypt(message, shift)
The same goes for decrypt.

Instead of printing, your functions should return the modified string. That way you could print the encoded message to the console, or email the message, or have it printed in invisible ink. You could also pass the encrypted message as an argument to the decrypt() function to decrypt the encrypted message.
shift = int(input("Enter shift: ")
message = input("Enter Message: ")
message = encrypt(message, shift)
print(f'The encrypted message is "{message}"')
message = decrypt(message, shift)
print(f'The decrypted message is "{message}"')
Reply


Messages In This Thread
RE: Help with function - encryption - messages - NameError: name 'message' is not defined - by deanhystad - Nov-11-2022, 09:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  I'm getting a NameError: ...not defined. vonArre 2 520 Mar-24-2024, 10:25 PM
Last Post: vonArre
  Variable is not defined error when trying to use my custom function code fnafgamer239 4 690 Nov-23-2023, 02:53 PM
Last Post: rob101
  Printing the variable from defined function jws 7 1,545 Sep-03-2023, 03:22 PM
Last Post: deanhystad
  Getting NameError for a function that is defined JonWayn 2 1,195 Dec-11-2022, 01:53 PM
Last Post: JonWayn
  How to print the output of a defined function bshoushtarian 4 1,410 Sep-08-2022, 01:44 PM
Last Post: deanhystad
  [split] NameError: name 'csvwriter' is not defined. Did you mean: 'writer'? cathy12 4 3,555 Sep-01-2022, 07:41 PM
Last Post: deanhystad
  NameError: name ‘app_ctrl’ is not defined 3lnyn0 0 1,615 Jul-04-2022, 08:08 PM
Last Post: 3lnyn0
  User-defined function to reset variables? Mark17 3 1,766 May-25-2022, 07:22 PM
Last Post: Gribouillis
  NameError: name 'hash_value_x_t' is not defined Anldra12 5 2,036 May-13-2022, 03:37 PM
Last Post: deanhystad
  NameError: name 'cross_validation' is not defined tmhsa 6 13,682 Jan-17-2022, 09:53 PM
Last Post: TropicalHeat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020