Silver Announcements


Lesson 17: Drawing with Turtle

posted Apr 12, 2019, 8:08 AM by Attila Lengyel   [ updated Apr 12, 2019, 8:12 AM ]

import turtle

bob = turtle.Turtle()

bob.forward(50)
bob.left(90)
bob.forward(50)

bob.left(90)
bob.forward(50)

bob.left(90)
bob.forward(50)

bob.clear()

for i in range(4):
bob.forward(100)
bob.right(90)

bob.clear()

bob.pencolor("red")

num_side = 6
side_length = 100
angle = 360 / num_side

for i in range(num_side):
bob.forward(side_length)
bob.right(angle)

bob.clear()

for i in range(5):
if i == 1 or i == 3: bob.penup()
bob.forward(50)
bob.right(144)
if i == 1 or i == 3: bob.pendown()

bob.clear()

for i in range(10):
bob.forward(i * 20)
bob.right(144)

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

bob.speed(2)
colors = ['red', 'purple', 'blue', 'green', 'orange', 'yellow']
for x in range(100):
bob.pencolor(colors[x%6])
bob.circle(5*x)
bob.circle(-5*x)
bob.left(x)


Lesson 16: What is a palindrome?

posted Apr 5, 2019, 8:04 AM by Attila Lengyel

def eliminate(w):
tmp = ""
for i in w:
if i.isalnum():
tmp = tmp + i.lower()

return tmp

word = input("Give me a word:")
word = eliminate(word)

reverse = ""
for i in word:
reverse = i + reverse
print(reverse)

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


Lesson 15: Hangman v1

posted Mar 29, 2019, 8:00 AM by Attila Lengyel

cl = ""
wl = " "
def draw(word, cl, wl):
a = ""
for c in word:
if c in cl:
a += c + " "
else:
a += "_ "
print(a)
if "_" not in a:
return "win"
elif len(wl) > 7:
return "lost"
else:
return "next"
word = input("Give me a word:")
status = draw(word, cl, wl)
while status == "next":
g = input("Guess a letter:")
if g in word and g not in cl:
cl += g
elif g not in wl:
wl += g
status = draw(word, cl, wl)
if status != "next":
print(status)

Lesson 14: Odd, even and prime numbers with modulo

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

import random as r

number = r.randint(0,1000)

if number % 2 == 0:
print(number, "is an even number")
else:
print(number, "is odd number")

#list up prime numbers
prime = [2,3,5,7,11]
while len(prime) < 1000:
nextnum = prime[len(prime) - 1]
stop = False

while stop == False:
nextnum += 1
isPrime = True
for i in prime:
if nextnum % i == 0:
isPrime = False
break
if isPrime:
prime.append(nextnum)
stop = True
print(prime)

Number guessing game user vs computer

posted Mar 15, 2019, 11:03 AM by Attila Lengyel

def guessgame(guess, n):
if guess == n:
return 0
elif guess < n:
return -1
else:
return 1

import random as r
n = r.randint(0,100)
counter = 0

guessed = False
while (guessed == False):
guess = int(input("What number did I think of?:"))
counter += 1
result = guessgame(guess, n)
if result == 0:
guessed = True
elif result == -1:
print("Too low")
else:
print("Too high")

print("Good guess! The number is", n, " You tried", counter, "times")

import math

print("Now you think of a number between 0 and 100!")
upper = 100
lower = 0
answer =""

while answer != "good":
guess = lower + math.floor((upper - lower)/2)
print("Is it", guess, "? (high/low/good):")
answer = input()

if answer == "high":
upper = guess
elif answer == "low":
lower = guess
else:
print("I made it!!! The number is", guess)


Scrambled words: the rset can be a toatl mses and you can sitll raed it wouthit porbelm

posted Feb 15, 2019, 8:05 AM by Attila Lengyel

import random
def randomize(word):
if len(word) < 3:
return word
chars = []
for i in word: #this stores every characters in a list
chars.append(i)
result =[]
result.append(chars[0]) # stores the first character
del chars[0] #deletes from the list
result.append(chars[len(chars)-1]) # stores the last character
del chars[len(chars)-1] #delets the last character
while len(chars) != 0:
r = random.randint(0,len(chars)-1)
result.insert(1, chars[r]) #inserts into the second position
del chars[r]
randomword = ""
for i in result: #appends the random list of characters
randomword += i
return randomword #returns randomword

text = "the rest can be a total mess and you can still read it without problem"
sentance = ""
for i in text.split(" "):
sentance += randomize(i) + " "
print(sentance)

Lesson 12: Rolling the dice

posted Feb 1, 2019, 7:57 AM by Attila Lengyel

import random as r

print(r.randint(1,6))

rolls = []
for i in range(0, 10000):
rolls.append(r.randint(1,6))

print(rolls)

for i in range(1,7):
print(i,rolls.count(i))

#This is to list all the possible combinations of rolling 2 dice
for i in range(1,7):
for j in range(1,7):
print(i,j, i + j)

rolls.clear()

#Roll the two dice 10,000 times and store in rolls list
print("Rolling two dice")
for i in range(0,78099):
a = r.randint(1,6)
b = r.randint(1,6)
rolls.append(a + b)

for i in range(2,13):
print(i, rolls.count(i), rolls.count(i) / len(rolls))

Lesson 11: Bubble sort

posted Jan 25, 2019, 8:05 AM by Attila Lengyel

names = ["Attila"]

name = ""
while name != "exit":
name = input("Give me a name:")
if name == "exit":
continue

if name in names:
print("You already have this name!")
continue

for i in range(0, len(names)):
if name < names[i]:
names.insert(i, name)
break
if i == len(names) - 1:
names.append(name)

print(names)

Lesson 10: Lists

posted Jan 18, 2019, 8:03 AM by Attila Lengyel

names = ["Kayden"]

names.append("Soham")
names.append("Jerry")
names.append("Kian")
names.append("Mahin")
names.append("Anshay")
names.append("Karthik")
names.append("William")
names.append("Sumedh")
names.append("Yahia")

print(names)

for name in names:
print("Hello", name, "!!!")

print("There are", len(names) - 1, "students in the class!")

print(names[0])
names.insert(2, "Attila")

print(names)

if "Mahin" in names:
print(names.index("Mahin"))
print(names[names.index("Mahin")])

names.sort()
print(names)

names.sort(reverse=True)
print(names)

import random, time

print(.9**20)

length = len(names)
for i in range(length):
select = random.randint(0, len(names)-1)
print(names[select], "stand up!!!")
names.remove(names[select])
time.sleep(3)

Lesson 9: Fibonacci series and more

posted Jan 11, 2019, 7:58 AM by Attila Lengyel

a = 0
b = 1
c = 1

print(a)
print(b)
print(c)

for i in range(0,100):
d = a + b + c
print(d)
a = b
b = c
c = d


1-10 of 87