Bronze Announcements


Lesson 17: Practice makes master

posted Feb 25, 2020, 8:05 AM by Attila Lengyel

a = int(input("Give me a number:"))
b = int(input("Give me an other:"))
print(a + b)

print("\n\n First 100 numbers")
num = []
for i in range(0,101):
num.append(i)
print(num)

print("\n\n\nEven numbers only:")
num.clear();
for i in range(0,101):
if i%2 == 0:
num.append(i)
print(num)

import turtle as t
bob = t.Turtle()
for i in range(0,4):
bob.forward(100)
bob.left(90)

Lesson 16: Nested loops with Turtle

posted Feb 11, 2020, 8:01 AM by Attila Lengyel   [ updated Feb 11, 2020, 8:02 AM ]

import turtle as t
import random as r

goo = t.Turtle()
goo.speed(0)
colors = ['red', 'orange', 'magenta', 'green', 'blue', 'yellow']

for k in range(0,8):
for i in range(0,8):
x = -180 + i * 50
y = 180 - k * 50
goo.penup()
goo.setposition(x,y)
goo.pendown()
goo.color(r.choice(colors))
goo.begin_fill()
for j in range(0,4):
goo.right(90)
goo.forward(40)
goo.end_fill()



for i in range(0,5):
for j in range(0,5):
print(i, "x", j, "=", i * j)



Lesson 15: Turtle in the box

posted Feb 4, 2020, 8:00 AM by Attila Lengyel

import turtle as t
john = t.Turtle()

john.shape("turtle")
john.fillcolor("blue")
john.pencolor("blue")
screen = t.Screen()

john.penup()
john.setposition(-200,200)
john.pendown()
john.forward(400)
john.right(90)
john.forward(400)
john.right(90)
john.forward(400)
john.right(90)
john.forward(400)
john.setposition(0,0)

def geofence():
if john.ycor() > 190: return False
if john.ycor() < -190: return False
if john.xcor() > 190: return False
if john.xcor() < -190: return False
return True

def move_forward():
speed = 10
if geofence() == False :
john.setposition(0,0)
john.pencolor("blue")
john.forward(speed)
def move_backward():
speed = 10
if geofence() == False :
john.setposition(0,0)
john.pencolor("white")
john.backward(speed)
def turn_right():
john.right(10)
def turn_left():
john.left(10)
def clear_screen():
john.clear()
def start_draw():
john.pendown()
def stop_draw():
john.penup()

screen.onkey(move_forward, "Up")
screen.onkey(move_backward, "Down")
screen.onkey(turn_right, "Right")
screen.onkey(turn_left, "Left")
screen.onkey(clear_screen, "c")
screen.onkey(stop_draw, "u")
screen.onkey(start_draw, "d")

screen.listen()

Lesson 14: Controlling the turtle

posted Jan 28, 2020, 8:03 AM by Attila Lengyel

import turtle as t
john = t.Turtle()

john.shape("turtle")
john.fillcolor("blue")
john.pencolor("blue")
screen = t.Screen()

def move_forward():
john.pencolor("blue")
john.forward(10)
def move_backward():
john.pencolor("white")
john.backward(10)
def turn_right():
john.right(10)
def turn_left():
john.left(10)
def clear_screen():
john.clear()
def start_draw():
john.pendown()
def stop_draw():
john.penup()

screen.onkey(move_forward, "Up")
screen.onkey(move_backward, "Down")
screen.onkey(turn_right, "Right")
screen.onkey(turn_left, "Left")
screen.onkey(clear_screen, "c")
screen.onkey(stop_draw, "u")
screen.onkey(start_draw, "d")

screen.listen()

Lesson 13: Drawing letter S with Turtle

posted Jan 21, 2020, 10:08 AM by Attila Lengyel

import turtle
def draw_s(t, x, y):
min_y = 100000
max_y = -100000
t.penup()
t.setpos(x, y)
t.pendown()
t.left(90)

for i in range(27):
t.left(10)
t.forward(1)
if t.ycor() < min_y:
min_y = t.ycor()
if t.ycor() > max_y:
max_y = t.ycor()

for i in range(27):
t.right(10)
t.forward(1)
if t.ycor() < min_y:
min_y = t.ycor()
if t.ycor() > max_y:
max_y = t.ycor()
print(min_y, max_y)

bob = turtle.Turtle()
draw_s(bob, -130,130)

Lesson 12: Turtle is here... simple drawing with Python Turtle

posted Jan 14, 2020, 8:05 AM by Attila Lengyel

import turtle as t

jojo_siwa = t.Turtle()

jojo_siwa.forward(50)
jojo_siwa.right(90)

jojo_siwa.forward(50)
jojo_siwa.right(90)

jojo_siwa.forward(50)
jojo_siwa.right(90)

jojo_siwa.forward(50)
jojo_siwa.right(90)


for i in range (0,4):
jojo_siwa.forward(50)
jojo_siwa.left(90)

jojo_siwa.clear()

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

jojo_siwa.clear()

num_sides = int(input("How many sides:"))
side_length = int(input("Length:"))

angle = 360 / num_sides
for i in range(0,num_sides):
jojo_siwa.forward(side_length)
jojo_siwa.right(angle)


jojo_siwa.done()


Lesson 11: Prime numbers and functions

posted Jan 7, 2020, 8:01 AM by Attila Lengyel

print(10%2)

for i in range(1,10):
print("10 modulo", i, "is", 10%i)


n = int(input("Give me a number:"))

prime = True
for i in range(2, n):
if n%i == 0:
prime = False
break

if prime == False:
print(n, "is not a prime number")
else:
print(n, "is a prime number")

def isprime(n):
prime = True
for i in range(2,n):
if n%i == 0:
prime = False
break
return prime

if isprime(n) == False:
print(n, "is not a prime number")
else:
print(n, "is a prime number")

for i in range (1,1000):
if isprime(i):
print(i)

Lesson 10: Binary search

posted Dec 17, 2019, 8:16 AM by Attila Lengyel

upper = int(input("Give me the max:"))
lower = int(input("Give me the min:"))

guess = int(input("Guess a number in between:"))

while guess > upper or guess < lower:
print("Wrong number! Try again.")
guess = int(input("Guess a number in between:"))


import math

print(math.ceil(34.7))
print(math.floor(34.7))

xyx = math.floor((upper + lower)/2)
while xyx != guess:
print("Is it", xyx,"?")
answer= input("yes or no?:")
if answer == "no":
answer = input("Is it lower or higher?")
print(answer)
if answer == "lower":
upper = xyx
else:
lower = xyx
xyx = math.floor((upper + lower)/2)


Lesson 9: Rolling the dice

posted Dec 10, 2019, 8:03 AM by Attila Lengyel   [ updated Dec 12, 2019, 7:59 AM ]

import random as r

print("Let's roll the dice!")
print("I rolled", r.randint(1,6))

rolls = [0,0,0,0,0,0]

for x in range(0,1000):
roll = r.randint(1,6)
rolls[roll-1] = rolls[roll-1] + 1

print(rolls)

total = sum(rolls)

for x in range(0,6):
prob = (rolls[x] / total) * 100
print("The probablity to roll", x + 1, "is", prob, "%")

rolls2 = [0,0,0,0,0,0,0,0,0,0,0,0]
for x in range (0,1000000):
d1 = r.randint(1,6)
d2 = r.randint(1,6)
rolls2[d1+d2-1] = rolls2[d1+d2-1] + 1

for x in range(0,12):
print(x + 1, rolls2[x])

Lesson 8: Fibonacci sequence with for loop and list

posted Dec 3, 2019, 7:56 AM by Attila Lengyel

a = 1
b = 1
c = a + b

print(a,b,c)

a = b
b = c
c = a + b

print(a,b,c)

a = b
b = c
c = a + b

print(a,b,c)

print("I'm the while loop")
i = 0
while i < 10:
a = b
b = c
c = a + b
print(a,b,c)
i = i + 1

print("I'm the for loop")
for x in range(0,10):
a = b
b = c
c = a + b
print(a,b,c)

f = [1,1,2]
for x in range(0,22):
f.append(f[len(f)-1] + f[len(f)-2])
print(f)



1-10 of 62