Python Forum
edit rotate function to consider capitalized letter
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
edit rotate function to consider capitalized letter
#1
I need to edit my rotate function to consider capital letters but I am confused on how to do that. Any help is appreciated. Thank you.

import rotate

def rotate(letter, rot):
    pos = alphabet_position(letter)
    new_pos = (pos + rot) % 26
    new_char = alphabet_pos[new_pos]

    return new_char
Error:
Traceback ︎For vigenere.encrypt('The crow flies at midnight!', 'boom') You should have returned this: 'Uvs osck rmwse bh auebwsih!' But you actually returned this: 'uvs osck rmwse bh auebwsih!' ✖ ︎For vigenere.encrypt('BaRFoo', 'BaZ') You should have returned this: 'CaQGon' But you actually returned this: 'caqgon' ✖ ︎For vigenere.encrypt('Sailing <3 ships thru br0ken harbors', 'NeilYoung') You should have returned this: 'Feqwgba <3 fnvta effo ox0xiv syfvbxf' But you actually returned this: 'feqwgba <3 fnvta effo ox0xiv syfvbxf'
Reply
#2
Personally, I would need more information about your program. What's it doing (on the hole) what's its purpose? Also, what are 'letter' and 'rot'; what is their type and where are they coming from. That being said, you might try some type of string comprehension.
Reply
#3
You need to check if the original letter is capitalized (isupper method), and if it is you need to make the new letter capitalized (upper method).
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  rotate error function schniefen 0 933 Dec-07-2022, 02:40 PM
Last Post: schniefen

Forum Jump:

User Panel Messages

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