Generating Random Dictionary Items

I am creating a text based office management game.
What I have been attempting is making people with random names, skills, efficiency levels and energy levels, so that the player can have randomly generated people that they can choose to hire or not.

So far I have been unable to set it up.

Here is the code that I have for the player to choose between which people to hire:

def Hiring():
	if len(Empty_Roles) == 0:
		print('You have no roles to fill, expand the building to have a higher capacity for workers.')
		break
	print('You have empty role(s) to fill.')
	for i in Empty_Roles:
		print('You are filling the ', i, ' job.')
		for i in Hiring_Opt:
			print('Name: ', i['name'], end='     ')
			print('Wage: ', i['wage'], end='     ')
			print('Skills: ', i['skills'], end='     ')
			print('Efficiency: ', i['efficency'], end='     ')
			print('Energy: ', i['energy'], end='     \n')
		Hired = input('Who would you like to hire?')

Can anyone offer a solution to generating them?

from random import randint, choice, sample

names =  ['Bob', 'Mike', 'Anna', 'Claire']
skills = ['word', 'excel', 'python', 'c#', 'java']

def get_ho():

    return {'Name      ':choice(names),
            'Wage      ':randint(20, 30)*100,
            'Skills    ':sample(skills, 3),
            'Efficiency':randint(5, 10),
            'Energy    ':randint(5, 10)
            }


for i in range(10):

    print(get_ho())

And for printing:


ho = get_ho()

for key, value in ho.items():

    print(f'{key}\t\t\t{', '.join(value) if isinstance(value, list) else value}')
1 Like

Thank you very much for this reply, – apologies if this is a dumb question – but how would I change this so that it generates three people to choose from and stores them in a dictionary so that their values are kept if they were hired?

Ok, I saw some of your other posts. Looks a bit like:
“If all you have is a hammer, everything looks like a nail.”

Why do you want to solve everything using dictionaries?
Go through all the topics up until and including ‘arrays’ (lists) here:
w3schools.com/python

As for your question, here’s a function that returns a list of candidates:

from random import randint, randrange, choice, sample

def get_candidates(n):

    names = ['Bob', 'Mike', 'Anna', 'Claire']
    skills = ['word', 'excel', 'python', 'c#', 'java']

    def gen_can():
        return {'Name      ': choice(names),
                'Wage      ': randrange(1500, 3000, 250),
                'Skills    ': sample(skills, 3),
                'Efficiency': randint(5, 10),
                'Energy    ': randint(5, 10)
                }

    return [gen_can() for _ in range(n)]

Thank you very much for the ding-bat-ish response. This is probably the most helpful thing I’ve ever seen in my nine hundred year life.
I have already read through the w3schools, and I obviously know about lists because to be able to learn dictionaries and not know about lists is a feat only achievable by Forrest Gump.

I want it to be stored in a dictionary because that is the most efficient way to store and reference that sort of data and so that I can directly transfer that to a dictionary where I am storing the people that have been hired; so that I can calculate how much money they make and all that.

I’m not sure I’ve understood your concern correctly, but you seem to have misunderstood how lists work.

If you have a non-primitive object, such as a dict or an object, both lists and dicts store pointers to the object. Passing around these pointers is both almost free and easy. eg:

my_dict['x'] = my_list[3]
for y in my_list:
  break
my_dict['y'] = y

In all of the above it doesn’t matter in any sense what objects are stored in the list. You’ve just created some new pointers to these objects.