120 likes | 337 Views
Vaja. Prebere ime in starost – izpiše „tvoje ime je jakob in si star 18 let“ Prebere stranico kocke in izpiše njen volumen in površino. (POW(,) **) Imamo znesek v €. Imamo bankovce po 100€, 50€, 20€, 10€, 5€ in 1€. Program naj izpiše kak bi znesek predstavili s temi bankovci.
E N D
Vaja • Prebere ime in starost – izpiše „tvoje ime je jakob in si star 18 let“ • Prebere stranico kocke in izpiše njen volumen in površino. (POW(,) **) • Imamo znesek v €. Imamo bankovce po 100€, 50€, 20€, 10€, 5€ in 1€. Program naj izpiše kak bi znesek predstavili s temi bankovci. • 399€ = 3*po100+1*po50+2*po20+1*po5+4*po1
Python Turtle
Getting Started with Graphics Programming • >>> import turtle # Import turtle module • >>> turtle.showturtle() • >>> turtle.write("Welcome to Python") • >>> turtle.forward(100)
6 • Type the following commands to turn the arrowhead right 90 degrees, change the • turtle’s color to red, and move the arrowhead 50 pixels forward to draw a line, as • shown in Figure 1.15d: • >>> turtle.right(90) • >>> turtle.color("red") • >>> turtle.forward(50)
7 • Now, type the following commands to turn the arrowhead right 90 degrees, set the color to • green, and move the arrowhead 100 pixels forward to draw a line, as shown in Figure 1.15e: • >>> turtle.right(90) • >>> turtle.color("green") • >>> turtle.forward(100)
8. • Finally, type the following commands to turn the arrowhead right 45 degrees and move • it 80 pixels forward to draw a line, as shown in Figure 1.15f: • >>> turtle.right(45) • >>> turtle.forward(80)
1.9.2 Moving the Pen to Any Location • Restart Python and type the following command to move the pen to (0, 50) from (0, 0), as • shown in Figure 1.16b. • >>>fromturtleimport * • >>> goto(0, 50) #ni več besede turtle!!
Move • The center of the Turtle Graphics window is at the coordinates (0, 0). (b) Move to (0, 50). (c) Move the • pen to (50, –50). (d) Set color to red. (e) Draw a circle using the circle command
penup() pendown() • You can also lift the pen up or put it down to control whether to draw a line when the pen • is moved by using the penup() and pendown() commands. For example, the following • commands move the pen to (50, -50), as shown in Figure 1.16c. • >>> penup() • >>> goto(50, -50) • >>> pendown() • >>> color("red") • >>> circle(50) # Draw a circle with radius 50
Drawing the Olympic Rings Logo • 1 importturtle • 2 • 3 turtle.color("blue") • 4 turtle.penup() • 5 turtle.goto(-110, -25) • 6 turtle.pendown() • 7 turtle.circle(45) • 8 • 9 turtle.color("black")
10 turtle.penup() • 11 turtle.goto(0, -25) • 12 turtle.pendown() • 13 turtle.circle(45) • 14 • 15 turtle.color("red") • 16 turtle.penup() • 17 turtle.goto(110, -25) • 18 turtle.pendown() • 19 turtle.circle(45) • 20 • 21 turtle.color("yellow") • 22 turtle.penup() • 23 turtle.goto(-55, -75) • 24 turtle.pendown() • 25 turtle.circle(45) • 26 • 27 turtle.color("green") • 28 turtle.penup() • 29 turtle.goto(55, -75) • 30 turtle.pendown() • 31 turtle.circle(45) • 32 • 33 turtle.done()