【发布时间】:2021-09-22 17:10:18
【问题描述】:
我正在尝试为我的化学课列出一个术语列表,并能够打印出我所要求的定义。 I.E 我询问了帝国系统的定义,然后我得到了该术语的定义。我已经创建了所有变量并将它们设置为术语的定义,但是当我尝试打印某个定义时,它会打印我拥有的所有定义。
VolumeUnits = "gal, cup, table spoons, teaspoons, quart, ounces, pints"
MetricSystem = "Based on the meter, really just a stick, Based on powers of 10"
PreFixes = """kilo
hecto
deka
base
deci
centi
mili"""
Mass = "the amount of matter in an object, base unit is kilograms"
Weight = "the pull of gravity on a mass"
Volume = "lenght x width x height"
Random = "1L - dm^3. 1ml - cm^3"
Time = "base is seconds"
Temperature = "Celsius, kelvin"
SigFig = "the last number that can be measured with confidence"
Chemistry = "the study of matter and its properties and reactions"
Matter = "anything that takes up space and has mass"
input("What would you like to know?\n")
if "Imperial":
print(Imperial)
if "VolumeUnits":
print(VolumeUnits)
if "MetricSystem":
print(MetricSystem)
if "PreFixes":
print(PreFixes)
if "Mass":
print(Mass)
if "Weight":
print(Weight)
if "Volume":
print(Volume)
if "Random":
print(Random)
if "Time":
print(Time)
if "Temperature":
print(Temperature)
if "SigFig":
print(SigFig)
if "Chemistry":
print(Chemistry)
if "Matter":
print(Matter)```
【问题讨论】:
-
bool("Matter")始终为True。尝试使用value = input然后if value == "Matter:"。为了更有效地使用dict而不是松散的变量,所以你不需要那么多ifs -
请编辑问题以将其限制为具有足够详细信息的特定问题,以确定适当的答案。
标签: python