import random
import turtle
spiral = turtle.Turtle()
turtle.bgcolor("black")
spiral.color("cadet blue")
randomfive = random.randint(5,15)
spiral.pensize(randomfive)
randomfour = random.randint(20,75)
spiral.speed (randomfour)
randomthree = random.randint(200,500)
randomtwo = random.randint(5,20)
random = random.randint(10,360)
spiral.pendown()
for i in range(randomthree):
spiral.forward(i * randomtwo)
spiral.right(random)
def christmas ():
turtle.bgcolor("black")
for i in range(2):
turtle.speed (9999999)
coordone = random.randint (-300,300)
coordtwo = random.randint (-300,300)
right = random.randint (1,360)
turtle.penup()
turtle.goto (coordone,coordtwo)
turtle.pendown()
turtle.right(right)
for y in range (10):
turtle.speed(9999)
turtle.right(36)
for x in range (50):
turtle.color("red")
turtle.speed(99999)
turtle.pensize(x/5)
turtle.forward (x-(x-1))
turtle.penup()
turtle.goto (coordone,coordtwo)
turtle.pendown()
turtle.right(18)
for z in range (10):
turtle.speed(9999)
turtle.right(36)
for w in range (50):
turtle.color("green")
turtle.speed(99999)
turtle.pensize(w/3)
turtle.forward (w-(w-1))
turtle.penup()
turtle.goto (coordone,coordtwo)
turtle.pendown()
christmas()
当我尝试这个python说“AttributeError:'int'对象没有属性'randint'”(顺便说一下,这是整个代码)。请帮助解决这个问题。这个名字就是drops.py,所以这不是问题。
答案 0 :(得分:0)
import turtle
import random
def spiral():
turtle.bgcolor("black")
spiral = turtle.Turtle()
spiral.color("cadet blue")
randomfive = random.randint(5, 15)
spiral.pensize(randomfive)
randomfour = random.randint(0, 11)
spiral.speed(randomfour)
randomthree = random.randint(200, 500)
randomtwo = random.randint(5, 20)
randomone = random.randint(10, 360)
spiral.pendown()
for i in range(randomthree):
spiral.forward(i * randomtwo)
spiral.right(randomone)
spiral.penup()
def christmas():
turtle.bgcolor("black")
turtle.speed("fastest")
for i in range(2):
coordinate = random.randint(-300, 300), random.randint(-300, 300)
right = random.randint(1, 360)
turtle.penup()
turtle.goto(coordinate)
turtle.pendown()
turtle.right(right)
for y in range(10):
turtle.right(36)
for x in range(50):
turtle.color("red")
turtle.pensize(x / 5)
turtle.forward(1)
turtle.penup()
turtle.goto(coordinate)
turtle.pendown()
turtle.right(18)
for z in range(10):
turtle.right(36)
for w in range(50):
turtle.color("green")
turtle.pensize(w / 3)
turtle.forward(1)
turtle.penup()
turtle.goto(coordinate)
turtle.pendown()
spiral()
christmas()
turtle.done()