aStr = input("Enter a string message: ")
fW = eval(input("Enter a positive integer: "))
print(f"Right aligned is <{aStr:>fW}>")
so, this is my code, I would like to align the spaces according to the user input. Whenever I try to use eval or int in fW, it shows this error.
Traceback (most recent call last):
File "C:\Users\vmabr\Downloads\A1Q2.py", line 5, in <module>
print(f"Right aligned is <{aStr:fW}>")
ValueError: Invalid format specifier
May I know what's the fix?
aStr = input("Enter a string message: ") fW = int(input("Enter a positive integer: ")) print(f"Right aligned is <{aStr.rjust(fW)}>")evalfunction exists.evalis not safe to use, especially on unsanitized user input as you have done. See stackoverflow.com/q/1832940/843953