此特定代碼失敗,運行對於第一次迭代,但是,因爲它繼續它顯示以下錯誤:奔跑對於第一次迭代和在礦井的第二
Traceback (most recent call last):
File "test1.py", line 7, in <module>
if len((hex(s)[2:])) == 1:
TypeError: 'str' object is not callable
的代碼如下:
import turtle
t = turtle.Turtle()
s = 0
z = 30
for i in range(s,16777217):[enter image description here][1]
if len((hex(s)[2:])) == 1:
hex = '#' + '00000' + hex(s)[2:].upper()
elif len((hex(s)[2:])) == 2:
hex = '#' + '0000' + hex(s)[2:].upper()
elif len((hex(s)[2:])) == 3:
hex = '#' + '000' + hex(s)[2:].upper()
elif len((hex(s)[2:])) == 4:
hex = '#' + '00' + hex(s)[2:].upper()
elif len((hex(s)[2:])) == 5:
hex = '#' + '0' + hex(s)[2:].upper()
else:
hex = '#' + hex(s)[2:].upper()
t.color(hex)
t.circle(z)
s += 1
z += 1