擅长:python、mysql、java
<p>我只能理解你问题的一部分,所以,我已经尽力解释了</p>
<p>if条件已按原样工作。我认为您希望在elif条件中检索朋友(键)的名称,因此您可以尝试以下代码:</p>
<pre><code>Friends = { 'rolf' : 'blue', 'ronnie' : 'green', 'barbara' : 'purple', 'benny' : 'kaki', 'stewart' : 'yellow', 'mickey' : 'red' }
def greetagain():
friend = input("Enter your friend name or color? ")
if friend in Friends.keys():
print('Key matches')
print("Color associted to friend is:", Friends[friend])
elif friend in Friends.values():
for key, value in Friends.items():
if friend == value:
print('Color is present in list and associated by:', key)
else:
print('subscribe')
greetagain()
</code></pre>