- 1

Creating Calculator type program.

I play a silly game and am just tinkering around and am terrible at programming but I am trying to take a bunch of set values in the game and be able to take what I have in my inventory and calculate what I capable of doing with it. for instance. these are the attacks and you have to collect the right materials to do the attack. comic hand requires - 1 duck, 1 plunger shrink ray requires- 1 plier, 2 megaphone rock monster- 1 hydrant, 1 binocular tornado - 1 anvil, 1 propeller magnet - 1 binocular, 2 hydrants, 2 anvil. and so ..... I want the user to be able to input what they have in their inventory and the program spit out what attacks they have based on what materials they have. since I am pretty bad at this. the code I have so far is super basic. I got the first one to work just using some math tricks. but the others will be difficult that way. I think a dict with multiple keys would work but dont know how to do it. here is what I have so far. p = int(input('Enter Number of Plungers: ')) d = int(input('Enter Number of Ducks: ')) pl = int(input('Enter Number of Pliers: ')) m = int(input('Enter Number of Megaphones: ')) h = int(input('Enter Number of Hydrants: ')) bi = int(input('Enter Number of Binoculars: ')) a = int(input('Enter Number of Anvil: ')) pp = int(input('Enter Number of Propellers: ')) am = int(input('Enter Number of Ammo: ')) g = int(input('Enter Number of Gas: ')) b = int(input('Enter Number of Boots: ')) print("Plungers: ", p,"Ducks:", d, "Pliers: ",pl, "Megaphones:",m,"Hydrants:",h, "Binoculars:", bi, "Anvil:",a,"Propellers:",pp,"Ammo:",am,"Gas:",g,"Boots:",b) if p >= d: comichand = (p+d)-p print("Number of Comic Hands: ", int(comichand)) elif p <= d: comichand = (p+d)-d print("Number of Comic Hands: ", int(comichand)) any help would be greatful. :)

1st Apr 2018, 12:32 AM
Aric Dunn
Aric Dunn - avatar
4 Antworten
0
Tip: Use a dictionary for storing the input and to ask for input use a for loop and iterate over the dictionary if you don’t know: https://stackoverflow.com/questions/3294889/iterating-over-dictionaries-using-for-loops
1st Apr 2018, 12:37 AM
TurtleShell
TurtleShell - avatar
0
yeah I have seen that and many many others.. I have more then 1 key per item to loop through then comes the adding the right things together. its not clear to me.
1st Apr 2018, 12:42 AM
Aric Dunn
Aric Dunn - avatar
0
items = {"item1": 0, "item2": 0, "item3": 0} # input for key in items: items[key] = int(input("{}: ".format(key))) print() # new line # display for key in items: print("{}: {}".format(key, items[key])) Just add in the keys
1st Apr 2018, 12:50 AM
TurtleShell
TurtleShell - avatar
0
but i have up to 3 keys per item..
1st Apr 2018, 12:52 AM
Aric Dunn
Aric Dunn - avatar