from typing import Dict, Any
# Define a dictionary with type annotations
my_dict: Dict[str, int] = {
'apple': 1,
'banana': 2,
'cherry': 3
}
# Use the get method to retrieve values with a default
def get_or_default(dictionary: Dict[str, int], key: str, default: Any) -> Any:
return dictionary.get(key, default)
value1: int = get_or_default(my_dict, 'banana', 0) # Returns 2
value2: int = get_or_default(my_dict, 'orange', 0) # Returns 0 because 'orange' is not in the dictionary
print(value1) # Output: 2
print(value2) # Output: 0
t = UniqueResponder("one", "two", "three")
for i in range(12):
print(t.getAResponse())
var notes: [String: UniqueResponder] = {
var tempDict = [String: UniqueResponder]()
tempDict["triggers"] = UniqueResponder()
return tempDict
}()
func manualAddResponse(key: String, value: String) {
if notes[key] == nil {
notes[key] = UniqueResponder(value: value)
}
notes[key]?.addResponse(value)
}
func addSkill(skill: Skill) {
axSkillBundle.addSkill(skill)
for i in 0..<10 {
notes["triggers"]?.addResponse("grind \(skill.skillNotes(param: "triggers"))")
}
}
func setDefaultNote() {
notes["notes"] = UniqueResponder(value: "a bundle of several skills")
}
override func skillNotes(param: String) -> String {
if let response = notes[param]?.getAResponse() {
return response
}
return "notes unavailable"
}
func addGrindSkill(skill: Skill) {
axSkillBundle.addSkill(GamiPlus(skill: skill, axGamification: axGamification, gain: gain))
for _ in 0..<10 {
notes["triggers"]?.addResponse("grind \(skill.skillNotes(param: "triggers"))")
}
}
func addCostlySkill(skill: Skill) {
axSkillBundle.addSkill(GamiMinus(skill: skill, axGamification: axGamification, cost: cost))
for _ in 0..<10 {
notes["triggers"]?.addResponse("grind \(skill.skillNotes(param: "triggers"))")
}
}
public override func setDefaultNote() {
notes["notes"] = UniqueResponder(value: "a bundle of grind and reward skills")
}
override func skillNotes(param: String) -> String {
if param == "notes" {
return "plain hello world skill"
} else if param == "triggers" {
return "say hello"
}
return "note unavailable"
}
override func skillNotes(param: String) -> String {
if param == "notes" {
return "magic 8 ball"
} else if param == "triggers" {
return "ask a question starting with should I or will I"
}
return "note unavailable"
}