Oct-31-2019, 03:19 PM
Hello,
I have this assignment and it kinda works on the platform. What is the problem, the character input. If the input is more than one character, the code still prints that out. For the assignment, it needs to be only one character.
Example output:
Give the text: hippo
Give the character: x
xxxxxxx
xhippox
xxxxxxx
This works. Next one is the problem:
Give the text: sausage
Give the character: **
Invalid input! Type only one character!
Give the character: *
******************
**sausage**
******************
So the code does not register the new input. I kinda had a too long break between my assignments, so I have forgotten something. I'd be very happy for any assistance you might have for me, thanks :)
I have this assignment and it kinda works on the platform. What is the problem, the character input. If the input is more than one character, the code still prints that out. For the assignment, it needs to be only one character.
Example output:
Give the text: hippo
Give the character: x
xxxxxxx
xhippox
xxxxxxx
This works. Next one is the problem:
Give the text: sausage
Give the character: **
Invalid input! Type only one character!
Give the character: *
******************
**sausage**
******************
So the code does not register the new input. I kinda had a too long break between my assignments, so I have forgotten something. I'd be very happy for any assistance you might have for me, thanks :)
def lenght(x): while len(x) != 1: print("Invalid input! Type only one character!") cha = str(input("Give the character: ")) break def decoration(y, x): decorated = y * (len(x) + 2) + "\n" #top row decorated = decorated + y + x + y + "\n" #middle row decorated = decorated + y * (len(x) + 2) + "\n" #bottom row return decorated def main(): tex = str(input("Give the text: ")) cha = str(input("Give the character: ")) lenght(cha) decoration(cha,tex) plaque = decoration(cha, tex) print(plaque) main()