everyone. I am trying to solve a coding challenge as follows:
- get a string from the user. Afterward, ask the user "What would you like to do to the string?", allow the user to choose the next functionalities: "upper" - makes all the string upper case "lower" - makes all the string lower case " "spaces2newline" - reaplce all spaces in new lines ... print the result *Use a dictionary to "wrap" that menu
So, what I am getting from this is that I need to make a dictionary from which I can call commands and assign them to the string.
Obviously, this doesn't work:
commands = {"1" : .upper(), "2" : .lower(), "3" : .replace(" ",\n)}
user_string = input("Enter a string: ")
options = input("How would you like to alter your string? (Choose one of the following:)\n
\t1. Make all characters capital\n
\t2. Make all characters lowercase")
#other options as input 3, 4, etc...
But perhaps someone can recommend a way to make the idea work?
My main questions are:
- Can you somehow assign built-in functions to a variable, list, or dictionary?
- How would you call a function like these from a dictionary and add them as a command to the end of a string?
Thanks for any assisstance!