<p>你没有利用基本的数据结构。每当你想将一个值映射到另一个值时,你可能需要一个<em>字典</em>。当你有一个连续的项目列表时,你需要一个列表。在</p>
<pre><code>>>> # NASCAR Numbers
... # Display Driver Information Based on your Car Number Input
...
>>> print("\t\t\tWelcome to NASCAR Numbers!")
Welcome to NASCAR Numbers!
>>> print("\t\t Match Car Numbers to the Driver Names.")
Match Car Numbers to the Driver Names.
>>> cars = [] # Use a list to store the car information.
>>> cars.append({'driver': 'Jamie McMurray', 'make': 'Chevrolet', 'sponsor': 'Bass Pro Shops/Allstate'}) # Each individual car detail should be in a dictionary for easy lookup.
>>> cars.append({'driver': 'Brad Keselowski', 'make': 'Dodge', 'sponsor': 'Miller Lite'})
>>> inputnumber = input("\nWhat car number do you want to lookup?\n\nCar Number:\t#")
What car number do you want to lookup?
Car Number: #2
>>> driver = cars[inputnumber-1]['driver'] # Python lists start at zero, so subtract one from input.
>>> print("driver" + str(inputnumber))
driver2
>>> print(driver)
Brad Keselowski
</code></pre>
<p>顺便说一句:使用<code>input</code>是危险的,因为无论用户输入什么类型的内容都会被计算为python。考虑使用<code>raw_input</code>,然后手动将输入转换为整数。在</p>