@Charanpreet/

Lab 4.03 Example - Dancing turtle-1

Python (with Turtle)

No description

fork
loading

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.715897116158628","path":"main.py","file":{"path":"main.py","content":{"asEncoding":{"base64":"aW1wb3J0IHR1cnRsZQppbXBvcnQgcmFuZG9tCmNsYXNzIERhbmNpbmdUdXJ0bGUodHVydGxlLlR1cnRsZSk6CiAgZGVmIHNoaW1teShzZWxmKToKICAgIGZvciBfIGluIHJhbmdlKDYpOgogICAgICBzZWxmLmxlZnQoMzApCiAgICAgIHNlbGYucmlnaHQoMzApCgogICMgTW92ZSBpbiBhIHppZy16YWcuCiAgZGVmIHppZ196YWcoc2VsZik6CiAgICBzZWxmLmxlZnQoMzApCiAgICBmb3IgXyBpbiByYW5nZSg0KToKICAgICAgc2VsZi5yaWdodCg2MCkKICAgICAgc2VsZi5mb3J3YXJkKDIwKQogICAgICBzZWxmLmxlZnQoNjApCiAgICAgIHNlbGYuZm9yd2FyZCgyMCkKICAgIHNlbGYucmlnaHQoMzApCgogICMgTW92ZSBmb3J3YXJkIGFuZCBiYWNrd2FyZCAxMCB0aW1lcy4KICBkZWYgc2hha2Uoc2VsZik6CiAgICBmb3IgXyBpbiByYW5nZSgxMCk6CiAgICAgIHNlbGYuYmFja3dhcmQoMjApCiAgICAgIHNlbGYuZm9yd2FyZCgyMCkKICAKICAKICAjIENoYW5nZSBjb2xvciB0byBhIHJhbmRvbSBjb2xvci4KICBkZWYgY2hhbmdlX2NvbG9yKHNlbGYpOgogICAgcmVkX2NvbG9yID0gcmFuZG9tLnJhbmRpbnQoMCwgMjUwKQogICAgZ3JlZW5fY29sb3IgPSByYW5kb20ucmFuZGludCgwLCAyNTApCiAgICBibHVlX2NvbG9yID0gcmFuZG9tLnJhbmRpbnQoMCwgMjUwKQogICAgc2VsZi5jb2xvcihyZWRfY29sb3IsIGdyZWVuX2NvbG9yLCBibHVlX2NvbG9yKQoKICAjIFBvaW50IGluIHRoZSB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nVwKCkKZG9yb3RoeS5zcGVlZCgzKQpkb3JvdGh5LmdvdG8oMCwgMCkKZG9yb3RoeS5jaGFuZ2VfY29sb3IoKQpkb3JvdGh5LnNoaW1teSgpCmRvcm90aHkuY2hhbmdlX2NvbG9yKCkKZG9yb3RoeS5kb19iYWNrZmxpcCgpCmRvcm90aHkuY2hhbmdlX2NvbG9yKCkKZG9yb3RoeS5kb19iYWNrd2FyZHNfc2h1ZmZsZSgpCmRvcm90aHkuY2hhbmdlX2NvbG9yKCkKZG9yb3RoeS56aWdfemFnKCkKZG9yb3RoeS5jaGFuZ2VfY29sb3IoKQpkb3JvdGh5LnNoYWtlKCkKZG9yb3RoeS5jaGFuZ2VfY29sb3IoKQpkb3JvdGh5Lmp1bXBfdXBfYW5kX2Rvd24oKQo="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import turtle
import random
class DancingTurtle(turtle.Turtle):
  def shimmy(self):
    for _ in range(6):
      self.left(30)
      self.right(30)

  # Move in a zig-zag.
  def zig_zag(self):
    self.left(30)
    for _ in range(4):
      self.right(60)
      self.forward(20)
      self.left(60)
      self.forward(20)
    self.right(30)

  # Move forward and backward 10 times.
  def shake(self):
    for _ in range(10):
      self.backward(20)
      self.forward(20)
  
  
  # Change color to a random color.
  def change_color(self):
    red_color = random.randint(0, 250)
    green_color = random.randint(0, 250)
    blue_color = random.randint(0, 250)
    self.color(red_color, green_color, blue_color)

  # Point in the up direction. Then go up and down 3 times.
  # Then point back to the right.
  def jump_up_and_down(self):
    self.left(90)
    for _ in range(3):
      self.forward(40)
      self.backward(40)
    self.right(90)

  # Point in the up direction. Go up. Then do a 360 degree turn.
  # Come back down and then point to the right again.
  def do_backflip(self):
    self.left(90)
    self.forward(40)
    self.left(360)
    self.backward(40)
    self.right(90)

  # Move backwards 60 steps and forward 30 steps.
  # Repeat 6 times.
  def do_backwards_shuffle(self):
    for _ in range(6):
      self.backward(60)
      self.forward(30)


# Create a DancingTurtle and have it do some dance moves.
# Make sure to incorporate all of the dance moves.

dorothy = DancingTurtle()
dorothy.shape('turtle')
dorothy.penup()
dorothy.speed(3)
dorothy.goto(0, 0)
dorothy.change_color()
dorothy.shimmy()
dorothy.change_color()
dorothy.do_backflip()
dorothy.change_color()
dorothy.do_backwards_shuffle()
dorothy.change_color()
dorothy.zig_zag()
dorothy.change_color()
dorothy.shake()
dorothy.change_color()
dorothy.jump_up_and_down()
result
console