Ask your own question, for FREE!
Computer Science 8 Online
OpenStudy (dan815):

need some python help, is there is a way to generate different variable names in a loop

OpenStudy (dape):

What do you mean? Can't you use a list/array?

OpenStudy (dape):

Sorry, I just don't understand why you would need to generate new variable names, if you just need many variables you could just do for example x = [] for i in range(4): x.append(i) x[2] = 1000 Here I create an array and successively add the elements 0,1,2 and 3 to the array, then I change the third element (arrays start from 0) to 1000. I don't know if this is what you want or if I am just misunderstanding the question.

OpenStudy (dan815):

@dape

OpenStudy (dan815):

hey hey 1 second!! ill tell you exactly where i am stuck

OpenStudy (dan815):

iam really new to this programming stuff, i just started python a couple days ago

OpenStudy (dan815):

okay so i have this dictionary

OpenStudy (dan815):

with a key= the names of the places

OpenStudy (dan815):

keys*=names of the corresponding places

OpenStudy (dape):

Okay, what's the value?

OpenStudy (dan815):

and its values for each key are a list of information corresponding to each place

OpenStudy (dape):

Alright

OpenStudy (dan815):

now what I want to do with this dictionary is

OpenStudy (dan815):

I have this class called class card(object): it take take in the parameters position, price,rent,color....

OpenStudy (dan815):

what I want to do is to take each key, and instead of a value of list.. i want the value to be a card object

OpenStudy (dan815):

can yo do that? can you have a dictionary with object values

OpenStudy (dape):

Yeah, that works fine

OpenStudy (dan815):

#board_dict={} #for i in card_dict.keys: #board_dict[i]=card(board_dict[i][1],board_dict[i][2],board_dict[i][3],board_dict[i][4])

OpenStudy (dan815):

would a code like this work

OpenStudy (dan815):

would you like to see my program??

OpenStudy (dan815):

im making this monopoly game for fun

OpenStudy (dan815):

very early stages

OpenStudy (dan815):

board_dict={} for i in card_dict.keys(): board_dict[i]=card(board_dict[i][1],board_dict[i][2],board_dict[i][3],board_dict[i][4])

OpenStudy (dan815):

oh wait upp it shuld be card dicts for the stuff in the class parameter

OpenStudy (dan815):

board_dict={} for i in card_dict.keys(): board_dict[i]=card(card_dict[i][1],card_dict[i][2],card_dict[i][3],card_dict[i][4])

OpenStudy (dape):

So the values of card_dict is a list?

OpenStudy (dape):

If so that should work

OpenStudy (dan815):

its a dictionary

OpenStudy (dan815):

oh umm yes sir

OpenStudy (dan815):

its a list

OpenStudy (dape):

Yeah, then it should work fine, sounds fun!

OpenStudy (dan815):

yeah its pretty interesting

OpenStudy (dan815):

i found a neat way to add 200 everytime someone passes go, no matter how he passes it

OpenStudy (dape):

Just PM me if you would like any more help later on, but you seem to have got the hang of python pretty well

OpenStudy (dan815):

oh wow ya it worked!!

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!