有没有办法在Python中向映射添加更多元素?

2024-06-16 12:32:34 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图在Python映射中为疾病添加症状,但我无法添加症状,因为它给出了一个错误。有没有一种方法可以做到这一点?我如何获取输入,然后使用用户输入的症状计算最接近的疾病

代码如下:

diseases = {'Coronavirus':'fever', 'dry cough','tiredness',
'Common Cold': 'cough', 'cold',
'Heart Attack': 'pain', 'pressure', 'squeezing'}

symptoms = input("Please type your symptoms (If there are multiple then separate them by a ',') (Note: type all in small letters): ")

if symptoms == 'fever, dry cough, tiredness':
    print("Your disease is Coronavirus or cornavirus! Deadly Disease: Yes")

if symptoms == 'cough, cold':
    print("Your disease is Common cold, Deadly Disease: No, but must consult a doctor if sever.")

Tags: 症状youriftypecommonfever疾病dry
2条回答

这是一个字典,添加多个“症状”(在:)作为列表,因此介于[…]之间。使用以下代码:

diseases = {'Coronavirus': ['fever', 'dry cough','tiredness'], 'Common Cold': ['cough', 'cold'], 'Heart Attack': ['pain', 'pressure', 'squeezing']}

把它列为清单

diseases = {'Coronavirus':['fever', 'dry cough','tiredness'],
            'Common Cold':['cough', 'cold'],
            'Heart Attack':['pain', 'pressure', 'squeezing']}

相关问题 更多 >