<p><code>flightcost</code>是一个函数,您正在尝试打印它。
您实际想要打印的是这个函数的返回值,因此您应该调用它并将适当的参数传递给它:<code>print('\nHere is your flight cost: ', flightcost(time, aircraft))</code>。你知道吗</p>
<p>不过,您的代码还有一些问题,我修复了其中几个问题:</p>
<pre><code>#!/usr/bin/python2
aircraft = {1: 'Fighter Jet', 2: 'Airliner', 3: 'Bi-Plane', 4: 'Aerobatic Plane'}
ppm = {1: 2.25, 2: 1.75, 3: 1.00, 4: 1.50}
def flightcost(time, aircraft_code):
y = time
x = ppm.get(aircraft_code)
return x * y
time = input('\nHow many minutes would you like to fly? Please enter 5 - 60 numbers only! \n')
print('\nHere are the aircraft simulators we have: \n')
for code, airplane in aircraft.items():
print('{} {}'.format(code, airplane))
aircraft = input('\nType in the numeric code for the plane you prefer? \n')
print('\nHere is your flight cost: ' + str(flightcost(time, aircraft)))
</code></pre>
<p>在我修复的问题中:</p>
<ul>
<li>您在<code>ppm</code>dict的键中混合了飞机名称和id</li>
<li>您在<code>ppm</code>dict中混合了值的类型,它们都应该是float,而不是string。你知道吗</li>
<li><code>aircraft.code</code>不存在,应将飞机代码作为参数传递给<code>flightcost</code>函数。你知道吗</li>
<li>将调用调整为最终的<code>print</code>,以防止将输出显示为元组。你知道吗</li>
</ul>