jEngines = [
[["Aerotech 54mm Motor (J1799N)"], ["0.6"], ["1799"], ["1090"], ["540"]],
[["Cesaroni 54mm Motor (J760)"], ["1.7"], ["760"], ["1076"], ["576"]],
[["Aerotech 54mm Motor (J401FJ)"], ["2.8"], ["401"], ["912"], ["511"]],
[["Aerotech 54mm Motor (J800T)"], ["1.6"], ["800"], ["1134"], ["595"]],
[["Aerotech 38mm Motor (J825R)"], ["1.2"], ["825"], ["878"], ["497"]],
[["Cesaroni 38mm Motor (J94)"], ["6.8"], ["94"], ["660"], ["372"]],
[["Aerotech 38mm Motor (J425R)"], ["1.6"], ["425"], ["631"], ["364"]],
[["Aerotech 38mm Motor (J500G)"], ["1.4"], ["500"], ["654"], ["375"]],
[["Aerotech 38mm Motor (J420)"], ["1.6"], ["420"], ["635"], ["345"]],
[["Aerotech 38mm Motor (J340M)"], ["1.8"], ["340"], ["577"], ["365"]]
]
kEngines = [
[["Aerotech 54mm Motor (K456DM)"], ["2.9"], ["456"], ["1484"], ["866"]],
[["Aerotech 54mm Motor (K2050ST)"], ["0.7"], ["2050"], ["2086"], ["1292"]],
[["Cesaroni 54mm Motor (K300)"], ["8.4"], ["300"], ["2270"], ["1265"]],
[["Cesaroni 54mm Motor (K260)"], ["8.7"], ["260"], ["2047"], ["1149"]],
[["Cesaroni 54mm Motor (K1200)"], ["1.7"], ["1200"], ["1631"], ["960"]],
[["Cesaroni 54mm Motor (K2045)"], ["0.7"], ["2045"], ["1290"], ["716"]],
[["Cesaroni 54mm Motor (K940)"], ["1.8"], ["940"], ["1366"], ["768"]],
[["Cesaroni 54mm Motor (K630)"], ["2.7"], ["630"], ["1410"], ["912"]]
]
def heightPrint():
rEngine = input("Pick a class of engine a-l (lowercase):")
rEngine= rEngine+("Engines")
print("You have chosen class {}".format(rEngine))
print("These are the engines in class {}".format(rEngine))
for x in range 20:
print(eval(rEngine[0][x]))
上面是三维阵列的一部分,我正试图解决这个问题。这可能是一个非常混乱的方法,但我想能够打印引擎从阵列与/n后,每一个,但它不喜欢有方括号后的求值行,也不喜欢有一个str在方括号里
重要编辑:如我所知,使用
eval()
是不好的做法。如果您是唯一一个使用此工具的人,下面的解决方案很好,但是如果其他人访问此工具,此方法是危险的,因为输入print(1)#
将使程序打印一个带有所有含义的1。在接收到输入后,通过检查输入字符是否在允许的输入范围内,可以修复代码不过,实现这一点的“pythonic”方法是使用字典将名称映射到数组,并以这种方式获取数组
可以在访问引擎之前
eval()
将其作为数组进行访问我不知道你到底想打印什么,这个功能将得到你的名字“航空科技54mm电机(J1799N)”等
对于
kEngines
如您的帖子所示,函数将产生以下输出:相关问题 更多 >
编程相关推荐