这是我正在使用的(相关)代码。
它基本上要做的是获取塔,然后(假设)将数字移到正确的塔上。
movefr = input("What tower do you want to move the last block from? " + str(nums) + " ")
movef = int(movefr)
moveto = input("What tower do you want to move the block from tower" + movefr + " to? " + str(nums) + " ")
movet = str(moveto)
#move numbers
if movef == 1:
if movet == 2:
tower2.append(tower1[-1])
tower1.remove(tower1[-1])
elif movet == 3:
tower3.append(tower1[-1])
tower1.remove(tower1[-1])
elif movef == 2:
if movet == 1:
tower1.append(tower2[-1])
tower2.remove(tower2[-1])
elif movet == 3:
tower3.append(tower2[-1])
tower2.remove(tower2[-1])
elif movef == 3:
if movet == 1:
tower1.append(tower3[-1])
tower3.remove(tower3[-1])
elif movet == 2:
tower2.append(tower3[-1])
tower3.remove(tower3[-1])
它输出如下内容:
Tower1 = [5, 4, 3, 2, 1, 0]
Tower2 = []
Tower3 = []
What tower do you want to move the last block from? [1] 1
What tower do you want to move the block from tower1 to? [2, 3] 2
Tower1 = [5, 4, 3, 2, 1, 0]
Tower2 = []
Tower3 = []
有谁知道热解决这个问题?我已经尝试了所有我能想到的。
问题来源:stackoverflow
您的movet
是字符串类型:
movet = str(moveto)
更改为:
movet = int(moveto)
回答来源:stackoverflow
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。