-1

I have been stuck with this little problem on how to use the user input for "stop" in the range function and then mirror the string ( in this case the alphabet) back without getting double user input.

Plus now the code can only take a number but it woul be nice to enter a letter convert it to the right number for it's place in the alphabet. And use that for range! But I tried twisting and turning and im not getting agreeable results.

Thank you for your time and patience!

 def front_aplhabet():
    alphabet = ''
    for letter in range(0,  human):
        alphabet += chr(ord("a") + letter)
    return alphabet

# function to mirror front_aplhabet output
def back_alphabet(input):
    return input[::-1]


human = int((input("Please enter a letter: "))

palidrome_2 = front_aplhabet() + back_alphabet(front_aplhabet())

print(palidrome_2)

output example:

Please enter a letter: 5
abcdeedcba

The goal is to get the following:

Please enter a letter: "e"
abcdefgfedcba

Please be very critical I'm here to learn !

I have tried this too

def front_aplhabet():
    alphabet = ''
    for letter in range(0, int(goat)):
        alphabet += chr(ord("a") + letter)
    return alphabet

# function to mirror front_aplhabet output
def back_alphabet(input):
    return input[::-1]


human = (input("Please enter a letter: "))
goat = ord(human)

palidrome_2 = front_aplhabet() + back_alphabet(front_aplhabet())

print(palidrome_2)

output:

Please enter a letter: 5
abcdefghijklmnopqrstuvwxyz{|}~~}|{zyxwvutsrqponmlkjihgfedcba

The goal is to get the following:

Please enter a letter: "g"
abcdefgfedcba
MalcolmXYZ
  • 126
  • 8
  • Seriously, I didn't get what you need to do? Let's say you got 5 as input what you need to generate? a random palindrome with 5 letters or what??? – kaouther Nov 08 '20 at 21:07
  • @kaouther i made a edit to the end of the question I hope it's a bit more clear. – MalcolmXYZ Nov 08 '20 at 21:10

1 Answers1

1

It looks like you want to ask the user for a letter then list the previous letters along with the mirror.

Try this code

def front_alphabet(human):
    alphabet = ''
    for letter in range(0,  human):
        alphabet += chr(ord("a") + letter)
    return alphabet

# function to mirror front_aplhabet output
def back_alphabet(input):
    return input[::-1]


human = ord(input("Please enter a letter: ")) - 97  # convert lowercase letter to ascii

palidrome_2 = front_alphabet(human) + chr(human+97) + back_alphabet(front_alphabet(human))

print(palidrome_2)

Output

Please enter a letter: g
abcdefgfedcba
Mike67
  • 11,175
  • 2
  • 7
  • 15
  • Dear @Mike67 this worked, I definitly need to practice with ord and chr more. Thank you for the time and good answer! – MalcolmXYZ Nov 08 '20 at 21:14