【发布时间】:2019-12-25 06:38:19
【问题描述】:
具备 Python 初学者知识并尝试找出其中的逻辑。我的经验是 SQL,所以很难摆脱这种思维方式。
我希望用户从列表中选择一架飞机,并让程序采用相应的代码来提取每分钟的价格。
我尝试了不同的变体。您可以看到我设置列表的方式的差异,试图查看问题是否存在。
aircraft = {'1':'Fighter Jet','2':'Airliner','3':'Bi-Plane','4':'Aerobatic Plane'}
ppm = {'Fighter Jet':'2.25','2':1.75,'3':'1.00','4':1.50}
def flightcost(time, aircraft):
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: ', flightcost)```
Expected results if a user wants to fly for 10 minutes in the Fighter Jet Simulator:
'time = 10 minutes'
'aircraft = 1:Fighter Jet'
'ppm = 1:2.25'
'flightcost = time (10 minutes) * ppm (2.25)'
'flightcost = 22.50'
Results right now: '<function flightcost at 0x00845150>'
(The code on the end is always different depending on what I've entered)
Something is happening. Just not what I am expecting!!!
【问题讨论】:
-
你没有调用函数
flightcostinprint('\nHere is your flight cost: ', flightcost):你需要把它改成flightcost()。
标签: python list multipleselection