-4
我必須在python中執行一項任務。我已經做到了。但由於我的課程中使用的軟件是2.7版本,所以我需要從python 3.3運行我的代碼到2.7。該代碼在3.3版本中運行良好,但不在2.7版本中運行。因此,你們可以幫助我嗎? 這是我的代碼。如何將此代碼從版本3.3恢復到版本2.7
# selectRobot.py # # 2014-03-26 #
'''
The output will be like below:
what type of robot application you like choose?
a) assembly
b) spot welding
Then let say the customer choose a or b, it will go to next question:
2.How much the load you expect for the robot to carry?
a) 0-2 kg
b) 0-5 kg
And so on ...
This is just a start ... need to continue ...
until finished choosing all attributes of the desired robot.
'''
from __future__ import print_function
menu1 = \
'''Please choose the type of robot application ?
a) assembly
b) spot welding
Please enter a or b : '''
menu2 = \
'''What is the max load for this robot?
a) 0-5 kg
b) 6-10 kg
c) 11-15 kg
Please enter a, b or c : '''
menu3 = \
'''What is the reach for this robot?
a) 0-1 m
b) 1-2 m
Please enter a or b : '''
menu4 = \
'''What is the mounting for this robot?
a) floor
b) wall
Please enter a or b : '''
def showMenuGetChoice(menu, low, high):
while True:
reply = input(menu).lower()
if low <= reply and reply <= high:
return reply
else:
print("'", reply, "' was NOT in valid " \
'input range ', low, '..', high, sep = '')
modelsStr = [] # get empty list to hold models
solns = [] # get empty list to hold all possible solution lists
count = 0
for i, a in enumerate(['a', 'b']):
for j, b in enumerate(['a', 'b', 'c']):
for k, c in enumerate(['a', 'b']):
for m, d in enumerate(['a', 'b']):
count += 1
modelsStr.append('model_' + str(count))
solns.append([a,b,c,d])
# print(modelsStr)
def mainLoop():
robot_specs = [] # get an empty list
robot_specs.append(showMenuGetChoice(menu1, 'a', 'b'))
robot_specs.append(showMenuGetChoice(menu2, 'a', 'c'))
#print('So far, robot_specs =', robot_specs)
robot_specs.append(showMenuGetChoice(menu3, 'a', 'b'))
robot_specs.append(showMenuGetChoice(menu4, 'a', 'b'))
#print('So far, robot_specs =', robot_specs)
for i, lst in enumerate(solns):
if lst == robot_specs:
print(robot_specs, '==>', modelsStr[i])
return
print('There was an unexpected error ...')
more = True
while(more):
mainLoop()
reply = input('\nMore (y/n) ? ').lower()
if reply == 'n':
more = False
input("Press 'Enter' to continue/exit ... ")
你不想要一個問題的答案,但你希望讓別人來完成你的任務,因此你現在得到一個-1和我的主持人標誌。 – peterh
你的縮進是*遍佈整個地方*;因爲它代表你的代碼甚至不會運行。它太大了一塊去,只是在這裏修復。 –
你的**唯一的問題是'input()'函數;你已經使用'from __future__ import print_function',用'raw_input()'替換'input()',你就在那裏。 –