def PrintDT(Tennis):
print "Split on Tennis[0]"
for a in Tennis[1]:
print "If tennis[0] == a "
if isinstance(Tennis[1][a], str):
PrintDT(tennis)
else:
print "Return:>>>5*' 'Tennis[1][a]"
所以我应该实现的格式是:
Split on Outlook
If Outlook == Sunny
Split on Humidity
If Humidity == High
Return: No
If Humidity == Low
Return: Yes
If Outlook == Overcast
Return: Yes
If Outlook == Rain
Split on Wind
If Wind == Strong
Return: No
If Wind == Weak
Return: Yes
我认为我有递归程序,但知道我需要做正确的格式化。请帮助
答案 0 :(得分:2)
您需要从正在打印的字符串文字中取出变量名称。目前,您只是打印一堆不会更改的字符串,但如果从"
中删除变量名称,则应该没问题。如果我们知道Tennis
是什么会有所帮助,但这至少可以让你更接近正确的答案。
def PrintDT(Tennis):
print "Split on", Tennis[0]
for a in Tennis[1]:
print "If", tennis[0], "==", a
if isinstance(Tennis[1][a], str):
PrintDT(tennis)
else:
print "Return: " + Tennis[1][a]