这是我的词典:
Health = {'John' : 100}
Run Code Online (Sandbox Code Playgroud)
我想做的是,我想设置一个值可以为100的最大数量.所以,如果我键入:
Health['John'] += 10
print Health
Run Code Online (Sandbox Code Playgroud)
打印时,我希望'John'的值为100,因为该值的最大值可以是100.如果代码是:
Health = {'John' : 90}
Health['John'] += 12
print Health
Run Code Online (Sandbox Code Playgroud)
我希望这打印'John':100,因为最大值是100.得到它?谢谢
这是我的代码:
Adherent = "a person who follows or upholds a leader, cause, etc.; supporter; follower."
word=raw_input("Enter a word: ")
print word
Run Code Online (Sandbox Code Playgroud)
当我运行此代码并输入Adherent时,会生成Adherent一词.我如何才能将Adherent的定义改为弹出?
这是一本字典:
Vocab ={'Adherent' : " supporter; follower.",
'Incoherent' : "without logical or meaningful connection; disjointed; rambling",
'Inherent' : "existing in someone or something as a permanent and inseparable element, quality, or attribute"}
Run Code Online (Sandbox Code Playgroud)
我在循环中创建了一组简单的if语句:
while 1:
x = Vocab[random.choice(Vocab.keys())]
print x
t1=raw_input("What word matches this definition?: ")
if t1 in Vocab == True:
if Vocab[t1] == x:
print "That's correct!"
elif Vocab[t1] != x:
print "That's wrong!"
else:
print "That's not a word!"
raw_input("Hit 'enter': ")
Run Code Online (Sandbox Code Playgroud)
出于某些奇怪的原因,当用户输入字典中的键时,代码输出:
"That's not a word" …Run Code Online (Sandbox Code Playgroud)