I have a List based on the user input.[‘r’, ‘r’, ‘r’, ‘r’, ‘s’, ‘S’, ‘P’, ‘P’, ‘s’, ‘s’, ‘p’]
I want to print this list as[“Rock”,Rock",Rock",Rock",Scissors",Scissors", “Paper”, “Paper”,“Scissors”,Scissors",“Paper”] depending on the user input.
The user input may change. I want to display whatever user enters in terms of [“Rock”, “Paper”, “Scissors”].
Could you please help me with this?
We can and will help, but this looks very much like a homework exercise.
We ask that you supply your attempt at this and ask questions, as the
point is to learn by solving the problem yourself.
You have a list of inputs. You want them associated with words like
“Rock” etc. The normal way to do this in Python is with a mapping,
usually a dict, which is an object with keys (such as “r”) and
associated values (such as “Rock”). Example:
wordmap = {
'a': 'apple',
'b': 'banana',
}
When you access a mapping via a key your get a value:
f = 'a'
fruit = wordmap[f]
print(f, fruit)
should print:
a apple
Try writing some code on that basis and see how it goes. Return with the
code and questions. If you have error tracebacks, include them completely. Please don’t use screenshots, instead copy/paste the code
(and/or traceback) into the message as text between triple backticks: