I am creating a program that uses the Caesar cipher to encode and decode messages. So far I am building the groundwork, I am trying to get my list of characters the user gives me and make a list of integers using ord...So far all I am having trouble with is getting my integers that I have received back into a list.
import random
encode_decode = input("Do you want to encode, or decode? (e/d)")
shift_amount = input("Please enter the shift amount for your message")
if encode_decode == "e" or encode_decode == "E":
user_words_unrefined = input("Enter your message to encode!")
elif encode_decode == "d" or encode_decode == "D":
user_words_unrefined = input("Enter your message to decode!")
user_words_refined = list(user_words_unrefined)
Alphabet = [chr(i) for i in range(ord('a'), ord('z') + 1)]
Counter = 0
for i in range(len(user_words_refined)):
user_words_numbers = (ord(user_words_refined[Counter]))
user_numbers_list = [user_words_numbers]
print(user_numbers_list)
Counter += 1
Input ("Hello, Party people!") output it prints them all on seperate lines with square brackets around them...any ideas?
[72]
[101]
[108]
[108]
[111]
[44]
[32]
[80]
[97]
[114]
[116]
[121]
[32]
[112]
[101]
[111]
[112]
[108]
[101]
This should sort you out. see the comments in the code. I will be happy to provide further explanation if need be
user_numbers_list = [] #initialise the list
Counter = 0
for i in range(len(user_words_refined)):
user_words_numbers = (ord(user_words_refined[Counter]))
user_numbers_list.append(user_words_numbers) #add to the end of the list
print(user_numbers_list)
Counter += 1
The best bet is actually list comprehension... see Jordan Lewis's answer for a neater approach