Home > Software design >  How do you set the value in a key to either of two numbers in python dictionary?
How do you set the value in a key to either of two numbers in python dictionary?

Time:10-04

Good day everyone, I am trying to set the value of key "Ace" to be either 1 or 11. I mean in different instances it could be 1 or 11. Please how do I do this?

cards_value = {
  "Ace": 11,
  "Card1": 2,
  "Card2": 3,
  "Card3": 4,
  "Card4": 5,
  "Card5": 6,
  "Card6": 7,
  "Card7": 8,
  "Card8": 9,
  "JKQ": 10,
}

CodePudding user response:

You can do with random,

import random
cards_value = {
   "Ace": random.choice([1,11]),
   "Card1": 2,
   "Card2": 3,
   "Card3": 4,
   "Card4": 5,
   "Card5": 6,
   "Card6": 7,
   "Card7": 8,
   "Card8": 9,
   "JKQ": 10,
}
  • Related