vendredi 19 janvier 2018

Choosing random values from a dictionary and afterwards ordering it

I am trying to make a random class generator for COD WW2 and I'm almost done but I have one problem. I'm trying to choose random scorestreaks (in which I succeed), but when my program prints the scorestreaks they are not ordered from cheapest to most expensive. I understand that this is normally also not the case but I would like it differently.

So I have been thinking and I think that dictionaries would be the key but I'm a beginner to Python and I haven't really used dictionaries before.

This is my list with scorestreaks:

scorestreaks = ["Molotov Cocktail", "Recon Aircraft", "Counter Recon 
Aircraft", "Care Package", "Fighter Pilot", "Glide Bomb", "Flamethrower", 
"Mortar Strike", "Artillery Barrage", "Flak Guns", "Emergency Airdrop", 
"Fire Bombing Run", "Paratroopers", "Carpet Bombing", "Ball Turret Gunner"]

And this is my random choosing thing:

ss1 = random.choice(scorestreaks)
ss2 = random.choice(scorestreaks)
ss3 = random.choice(scorestreaks)
if ss1 == ss2 or ss1 == ss3:
    ss1 = random.choice(scorestreaks)
    if ss1 == ss2 or ss1 == ss3:
        ss1 = random.choice(scorestreaks)
elif ss2 == ss3:
    ss2 = random.choice(scorestreaks)
    if ss2 == ss3 or ss2 == ss1:
        ss2 = random.choice(scorestreaks)

print "Scorestreaks: %s, %s, %s" %(ss1, ss2, ss3)

So idealy I would like to have the scorestreaks ordered when they are printed from cheapest to most expensive. Thank you for your answer.




Aucun commentaire:

Enregistrer un commentaire