Bronze Announcements


2019-2020 Lesson 1: Hello World and some compute

posted Oct 8, 2019, 7:59 AM by Attila Lengyel

print("Hello World!")
name = input("What is your name?")
print("Hello", name)

#Let's do some math

number = 69587598 * 76485648654
print(number)
print(number)

print(56 * 78)

Lesson 22: Turtle in corners and timer

posted Jun 5, 2019, 8:05 AM by Attila Lengyel

import turtle as t

bob = t.Turtle()
bob.shape("turtle")
def move(x,y,corner):
bob.clear()
bob.speed(0)
bob.penup()
bob.goto(x,y)
bob.pendown()
for x in range(0,3):
bob.forward(40)
bob.left(120)

def turtlewrite(message):
bob.write(message, font=("Arial", 64, "normal"))

import time
import random

def select():
for x in range(0,7):
bob.clear()
turtlewrite(7 - x)
time.sleep(1)

corner = random.randint(1,4)
if corner == 1:
move(200, 200, 1)
elif corner == 2:
move(-200, 200, 2)
elif corner == 3:
move(-200, -200, 3)
else:
move(200, -200, 4)

for x in range(0,10):
select()
time.sleep(2)
move(0,0,0)

Lesson 21: Four corners

posted May 29, 2019, 7:52 AM by Attila Lengyel   [ updated May 29, 2019, 7:57 AM ]

import turtle as t

bob = t.Turtle()
bob.shape("turtle")


def move(x,y,corner):
bob.clear()
bob.speed(0)
bob.penup()
bob.goto(x,y)
bob.pendown()
for x in range(0,3):
bob.forward(40)
bob.left(120)

bob.write("Corner ", corner)

move(-200, 200, 2)
move(0,0,0)
move(200, 200, 1)
move(0,0,0)
move(-200, -200, 3)
move(0,0,0)
move(200, -200, 4)

Lesson 20: Catch me if you can

posted May 8, 2019, 7:34 AM by Attila Lengyel   [ updated May 8, 2019, 8:10 AM ]

import turtle as t
t1 = t.Turtle()
t1.shape("turtle")
t1.fillcolor("blue")
t1.pencolor("blue")

t2 = t.Turtle()
screen = t.Screen()

def draw_rectangle(player, x, y, width, height, color):
startpos = player.pos()
startcolor = player.pencolor()
player.pencolor(color)
player.up()
player.goto(x, y)
player.down()
player.forward(width)
player.left(90)
player.forward(height)
player.left(90)
player.forward(width)
player.left(90)
player.forward(height)
player.left(90)
player.up()
player.goto(startpos)
player.down()
player.pencolor(startcolor)

draw_rectangle(t1, -210, -210, 420, 420, "red")

def inbox(player):
if player.xcor() >= 200:
player.up()
player.goto(199, player.ycor())
player.down()
return False
if player.xcor() <= -200:
player.up()
player.goto(-199, player.ycor())
player.down()
return False
if player.ycor() >= 200:
player.up()
player.goto(player.xcor(), 199)
player.down()
return False
if player.ycor() <= -200:
player.up()
player.goto(player.xcor(), -199)
player.down()
return False
return True

def f():
if inbox(t1): t1.forward(10)
def b():
if inbox(t1): t1.backward(10)
def l(): t1.left(10)
def r(): t1.right(10)
screen.onkey(f, "Up")
screen.onkey(b, "Down")
screen.onkey(l, "Left")
screen.onkey(r, "Right")

def catch():
if t1.distance(t2) < 10:
t2.write("CATCH!!!")
def f2():
if inbox(t2) : t2.forward(10)
catch()
def b2():
if inbox(t2): t2.backward(10)
catch()
def l2(): t2.left(10)
def r2(): t2.right(10)

screen.onkey(f2, "s")
screen.onkey(b2, "x")
screen.onkey(l2, "z")
screen.onkey(r2, "c")
screen.listen()

Lesson 19: Turtle Race

posted May 1, 2019, 8:03 AM by Attila Lengyel

import turtle as t
t1 = t.Turtle()
t1.shape("turtle")
t1.fillcolor("blue")
t1.pencolor("blue")

t2 = t.Turtle()
screen = t.Screen()

def f(): t1.forward(10)
def b(): t1.backward(10)
def l(): t1.left(10)
def r(): t1.right(10)
screen.onkey(f, "Up")
screen.onkey(b, "Down")
screen.onkey(l, "Left")
screen.onkey(r, "Right")

def catch():
if t1.distance(t2) < 10:
t2.write("CATCH!!!")
t1.clear()
t2.clear()
def f2():
t2.forward(10)
catch()
def b2():
t2.backward(10)
catch()
def l2(): t2.left(10)
def r2(): t2.right(10)

screen.onkey(f2, "s")
screen.onkey(b2, "x")
screen.onkey(l2, "z")
screen.onkey(r2, "c")
screen.listen()

Lesson 18: Events handling with Turtle

posted Apr 17, 2019, 8:00 AM by Attila Lengyel

import turtle
screen = turtle.Screen()
turtle.shape("turtle")
turtle.fillcolor("blue")
turtle.pencolor("blue")
speed = 10
turn = 10

def f():
turtle.forward(speed)
turtle.fillcolor("red")
turtle.pencolor("red")

def b():
turtle.backward(speed)
turtle.fillcolor("blue")
turtle.pencolor("blue")

def l():
turtle.left(turn)

def r():
turtle.right(turn)

def c():
turtle.clear()

turtle.speed(0)

screen.onkey(f, "Up")
screen.onkey(b, "Down")
screen.onkey(l, "Left")
screen.onkey(r, "Right")
screen.onkey(c, "c")
screen.listen()

Lesson 17: Drawing with Turtle

posted Apr 10, 2019, 8:01 AM by Attila Lengyel

import turtle

ted = turtle.Turtle()

for i in range(0,4):
ted.forward(50)
ted.left(90)
ted.write("Turn left")

ted.penup()
ted.setposition(-100,-100)
ted.pendown()

for i in range(0,5):
ted.forward(50)
ted.right(144)

ted.clear()

ted.pencolor("blue")
ted.circle(100)

ted.clear()
ted.penup()
ted.setposition(0,0)
ted.pendown()

num_sides = 5
side_length = 10
angle = 360 / num_sides

for i in range(0,num_sides):
ted.forward(side_length)
ted.right(angle)

Lesson 16: What is a palindrome?

posted Apr 3, 2019, 7:53 AM by Attila Lengyel

word = input("Give me a sentence:")
tmp = ""
for i in word:
if i.isalnum():
tmp = tmp + i.lower()
word = tmp
s = ""

for i in word:
s = i + s

print(s)
print(word)

if s == word:
print("This is a palindrome")
else:
print("This is not a palindrome")

Lesson 15: Hangman v1

posted Mar 27, 2019, 8:05 AM by Attila Lengyel

word = input("Give me the hidden word:")

correctletters = ""
incorrectletters = ""

def drawhangman(word, correctletters, incorrectletters):
output = ""
for c in word:
if c in correctletters:
output += c + " "
else:
output += "_ "
print(output)

#drawhangman("rule", "eul", "")
#drawhangman("rule", "ul", "")
#drawhangman("rule", "l", "")
#drawhangman("rule", "", "")
#drawhangman("rule", "erul", "")

while len(word) != len(correctletters) and len(incorrectletters) < 8:
guess = input("Guess a letter:")
if guess in word and guess not in correctletters:
correctletters += guess
elif guess not in incorrectletters:
incorrectletters += guess
drawhangman(word, correctletters, incorrectletters)

Lesson 14: Binary search... for guessing

posted Mar 22, 2019, 7:18 AM by Attila Lengyel

print("Think of a number between 0 and 100!")

answer = ""

upper = 100
lower = 0

import math as m

while answer != "correct":
guess = m.floor((upper - lower)/2 + lower)
print("Did you guess", guess, "?")
answer = input()
if answer == "correct":
print("You thought of", guess,".")
elif answer == "low":
lower = guess
elif answer == "high":
upper = guess


1-10 of 47