This is my first post and I'm quite new at programming, so I might not be able to convey my question appropriately, but I'll do my best!
tries_dict = {1:'first', 2:'second', 3:'third', 4:'fourth', ub_tries:'last'}
ub_tries = user input
tries = 1
input ('\nCome on make your ' + tries_dict.get(tries) + guess: ')
These 3 elements are part of a number guess game I created, and I included them in a while
loop where tries += 1
after each wrong answer.
As you can see, in my dictionary there are custom values for the first 4 answers and the last possible chance before the game is over, so here is what I tried to do:
I wanted to find a way to have the 'NEXT' value for every answer/key between 'fourth' and 'last'.
As in:
tries = 5
Come on make your next guess
tries = 6
Come on make your next guess
and so on
I did find a way with some complex looping, but being the curious type I wanted to know of more efficient/practical ways to accomplish this.
Here are some options i thought about but couldn't get to work:
- Using a range as a key
- Finding a way to generate a list with values between 4 and
ub_tries
and using that list as a key
So generally speaking: how can one create a way to have this general answer (next or whatever) for keys that aren't specified in a dictionary?
Any feedback would be greatly appreciated, feel free to ask for clarifications since I can tell myself my question is kind of messy.
I hope I get more crafty both at programming and asking related questions, so far my programming is nearly as messy as my summary skills, sigh!