2015-11-25 99 views
0
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() 

當我嘗試這條巨蟒說「AttributeError的:‘詮釋’對象有沒有屬性‘randint’」(順便說一句,這是整個代碼)。請幫助解決這個問題。這個名字是droplet.py,所以不會是問題。如何運行這兩個龜腳本此起彼伏

+1

不要調用變量'random'。 – user2357112

回答

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()