0

I have been trying to create a Caesar cipher program. To make it as inclusive as possible I want to be able to use upper case letters as well. I know how to load a lower case alphabet:

alphabet = string.ascii_lowercase * 2

(I have timed it by two to allow the user to encrypt all letters) I would really like some help. It is my first time submitting a question and I would appreciate any help I get

4 Answers4

2

If there is a string.ascii_lowercase then surely there is a string.ascii_uppercase. Give it a try.

Malik Brahimi
  • 16,341
  • 7
  • 39
  • 70
0

You can use

string.uppercase This is locale-dependent, and value will be updated when locale.setlocale() is called.

Please refer - https://docs.python.org/2/library/string.html

Pralhad Narsinh Sonar
  • 1,406
  • 1
  • 14
  • 23
0

There is string.ascii_uppercase as well as string.ascii_lowercase (documentation). For testing if a letter is upper case and do something for uppercase letters in a message you can do this:

for letter in message:
    if letter in string.ascii_uppercase:
        # do something

You can also use isupper() method (documentation):

for letter in message:
    if letter.isupper():
        # do something

If you want to check whether the whole message is upper case, then isupper() is actually better as it checks the whole string:

if message.isupper():
    # do something
geckon
  • 8,316
  • 4
  • 35
  • 59
-1

This loop will make a string with all uppercase letters and save it in letters_str

letters_str = ''
for x in range(65,91):
    letters_str+=chr(x)
user9138
  • 21
  • 3