def babylonian(symbols):
table=[["T",1], ["<",10],["\\",0]]
returning=0
for pair in table:
forTrue=True
while forTrue:
if len(symbols)>=len(pair[0]):
if symbols[0:len(pair[0])]==pair[0]:
returning+=pair[1]
symbols=symbols[len(pair[0]):]
else:
forTrue=False
else:
forTrue=False
return returning
你好,我要做什么才能得到类似的输出:
print(babylonian(['TT', '<<']))
# should output [2,10]
print(babylonian(['<<T', 'TTT', '//', '<<<<TTT']))
# should output [21,3,0,43]
目前我只能从表中输出数字,如果我尝试堆栈ex.TT
,<<
,我得到的输出是0
我试着让它变得简单,这是我的第一次尝试:
相关问题 更多 >
编程相关推荐