http://sites.google.com/feeds/content/site/primaryprogrammers2019-10-14T23:09:03.217ZPosts of Silver AnnouncementsGoogle Sites1http://sites.google.com/feeds/content/site/primaryprogrammers/26311946250467844772019-06-07T15:07:54.280Z2019-06-07T15:07:54.287Z2019-06-07T15:07:54.274ZLesson 22: Draw THANK with turtle
 import turtle as ttt = t.Turtle()def draw_t(bob,x,y): bob.penup() bob.goto(x,y) bob.pendown() bob.forward(50) bob.left(180) bob.forward(25) bob.left(90) bob.forward(60) bob.left(90)def draw_h(bob,x,y): bob.penup() bob.goto(x,y) bob.pendown() bob.right(90) bob.forward(60) bob.left(180) bob.forward(30) bob.right(90) bob.forward(30) bob.left(90) bob.forward(30) bob.left(180) bob.forward(60) bob.left(90)def draw_a(bob, x,y): bob.penup() bob.goto(x,y) bob.pendown() bob.goto(x + 15, y + 60) bob.goto(x + 30, y + 0) bob.penup() bob.goto(x,y + 30) bob.pendown() bob.goto(x + 30, y + 30)def draw_n(bob, x, y): bob.penup() bob.goto(x,y) bob.pendown() bob.left(90) bob.forward(60) bob.goto(x + 30, y) bob.forward(60) bob.right(90)def draw_k(bob, x, y): bob.penup() bob.goto(x,y) bob.pendown() bob.right(90) bob.forward(60) bob.right(180) bob.forward(25) bob.goto(x + 30 ,y) bob.goto(x,y -35) bob.goto(x + 30 ,y - 60) draw_t(tt, -200, 200)draw_h(tt, -140, 200)draw_a(tt, -100, 140)draw_n(tt, -60, 140)draw_k(tt, -20, 200)
Attila Lengyelprimaryprogrammers@gmail.comlesson22drawthankwithturtle1
http://sites.google.com/feeds/content/site/primaryprogrammers/85755738342711216712019-05-31T15:00:25.282Z2019-05-31T15:00:25.295Z2019-05-31T15:00:25.275ZLesson 21: Turtle in corners
 import turtleimport timeimport randomt = turtle.Turtle()def draw(x,y, delay, s): t.clear() t.penup() t.goto(x,y) t.pendown() t.speed(s) for x in range(0,3): t.forward(50) t.left(120) time.sleep(delay)time.sleep(2)draw(0,0,3, 5)for x in range(0,10): time.sleep(1) corner = random.randint(1,4) if corner == 1: draw(200,200,0,0) elif corner == 2: draw(-200, 200,0,0) elif corner == 3: draw(-200, -200,0,0) else: draw(200, -200,0,0) time.sleep(2) draw(0,0,3)
Attila Lengyelprimaryprogrammers@gmail.comlesson21turtleincorners1
http://sites.google.com/feeds/content/site/primaryprogrammers/67240912186970567022019-05-10T14:41:07.401Z2019-05-10T15:04:42.820Z2019-05-10T15:04:41.730ZLesson 20: Catch me if you can
 import turtle as tplayer1 = t.Turtle()player1.shape("turtle")player1.pencolor("white")player1.fillcolor("blue")player2 = t.Turtle()player2.shape("turtle")player2.fillcolor("red")player2.pencolor("white")player2.goto(-180, 180)speed = 10angle = 10screen = 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(player1, -210, -210, 420, 420, "black")def position(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 Trueimport mathdef catch(playera, playerb): x1 = playera.xcor() y1 = playera.ycor() x2 = playerb.xcor() y2 = playerb.ycor() c = math.pow(x1-x2,2) + math.pow(y2-y1,2) c = math.sqrt(c) if c < 10: playera.fillcolor("red") playerb.fillcolor("blue") def f(): if position(player1): player1.forward(speed)def b(): if position(player1): player1.backward(speed)def r(): player1.right(angle)def l(): player1.left(angle)screen.onkey(f, "Up")screen.onkey(b, "Down")screen.onkey(r, "Right")screen.onkey(l, "Left")def f2(): if position(player2): player2.forward(speed) catch(player1, player2)def b2(): if position(player2): player2.backward(speed) catch(player1, player2)def r2(): player2.right(angle)def l2(): player2.left(angle)screen.onkey(f2, "q")screen.onkey(b2, "a")screen.onkey(r2, "x")screen.onkey(l2, "z")screen.listen()
Attila Lengyelprimaryprogrammers@gmail.comlesson20catchmeifyoucan2
http://sites.google.com/feeds/content/site/primaryprogrammers/51848286589366734422019-05-03T15:45:18.015Z2019-05-10T14:28:22.499Z2019-05-10T14:28:21.240ZLesson 18: Turtle in a box
 import turtle as tplayer1 = t.Turtle()player1.shape("turtle")player1.pencolor("white")speed = 10angle = 10screen = 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(player1, -210, -210, 420, 420, "red")def position(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 Truedef f(): if position(player1): player1.forward(speed)def b(): if position(player1): player1.backward(speed)def r(): player1.right(angle)def l(): player1.left(angle)screen.onkey(f, "Up")screen.onkey(b, "Down")screen.onkey(r, "Right")screen.onkey(l, "Left")screen.listen()
Attila Lengyelprimaryprogrammers@gmail.comlesson18turtleinabox2
http://sites.google.com/feeds/content/site/primaryprogrammers/85486046104277942972019-04-12T15:08:59.184Z2019-04-12T15:12:44.343Z2019-04-12T15:12:41.381ZLesson 17: Drawing with Turtle
 import turtlebob = 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 = 6side_length = 100angle = 360 / num_sidefor 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)
Attila Lengyelprimaryprogrammers@gmail.comlesson16drawingwithturtle2
http://sites.google.com/feeds/content/site/primaryprogrammers/21388117606767207762019-04-05T15:04:23.183Z2019-04-05T15:04:23.192Z2019-04-05T15:04:23.177ZLesson 16: What is a palindrome?
 def eliminate(w): tmp = "" for i in w: if i.isalnum(): tmp = tmp + i.lower() return tmpword = input("Give me a word:")word = eliminate(word)reverse = ""for i in word: reverse = i + reverseprint(reverse)if word == reverse: print("This is a palindrome")else: print("This is not a palindrome")
Attila Lengyelprimaryprogrammers@gmail.comlesson16whatisapalindrome1
http://sites.google.com/feeds/content/site/primaryprogrammers/11676401929189535212019-03-29T15:00:44.248Z2019-03-29T15:00:44.259Z2019-03-29T15:00:44.238ZLesson 15: Hangman v1
 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)
Attila Lengyelprimaryprogrammers@gmail.comlesson15hangmanv11
http://sites.google.com/feeds/content/site/primaryprogrammers/80984377552106100872019-03-22T14:56:43.607Z2019-03-22T14:56:43.616Z2019-03-22T14:56:43.602ZLesson 14: Odd, even and prime numbers with modulo
 import random as rnumber = r.randint(0,1000)if number % 2 == 0: print(number, "is an even number")else: print(number, "is odd number")#list up prime numbersprime = [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)
http://sites.google.com/feeds/content/site/primaryprogrammers/52133576157356873032019-03-15T18:03:52.026Z2019-03-15T18:03:52.035Z2019-03-15T18:03:52.018ZNumber guessing game user vs computer
 def guessgame(guess, n): if guess == n: return 0 elif guess < n: return -1 else: return 1import random as rn = r.randint(0,100)counter = 0guessed = Falsewhile (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 mathprint("Now you think of a number between 0 and 100!")upper = 100lower = 0answer =""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)
Attila Lengyelprimaryprogrammers@gmail.comnumberguessinggameuservscomputer1
http://sites.google.com/feeds/content/site/primaryprogrammers/25582539307974459692019-02-15T16:05:28.707Z2019-02-15T16:05:28.710Z2019-02-15T16:05:28.705ZScrambled words: the rset can be a toatl mses and you can sitll raed it wouthit porbelm
 import randomdef 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) # stores the first character del chars #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 randomwordtext = "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)
Attila Lengyelprimaryprogrammers@gmail.comscrambledwordsthersetcanbeatoatlmsesandyoucansitllraeditwouthitporbelm1
http://sites.google.com/feeds/content/site/primaryprogrammers/66607692155856935372019-02-01T15:57:54.540Z2019-02-01T15:57:54.543Z2019-02-01T15:57:54.536ZLesson 12: Rolling the dice
 import random as rprint(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 dicefor 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 listprint("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))
Attila Lengyelprimaryprogrammers@gmail.comlesson12rollingthedice1
http://sites.google.com/feeds/content/site/primaryprogrammers/45989197459572006862019-01-25T16:05:13.353Z2019-01-25T16:05:13.358Z2019-01-25T16:05:13.348ZLesson 11: Bubble sort
 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)
Attila Lengyelprimaryprogrammers@gmail.comlesson11bubblesort1
 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)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, timeprint(.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)
Attila Lengyelprimaryprogrammers@gmail.comlesson10lists1
http://sites.google.com/feeds/content/site/primaryprogrammers/42279852601881033552019-01-11T15:58:22.489Z2019-01-11T15:58:22.496Z2019-01-11T15:58:22.482ZLesson 9: Fibonacci series and more
 a = 0b = 1c = 1print(a)print(b)print(c)for i in range(0,100): d = a + b + c print(d) a = b b = c c = d
Attila Lengyelprimaryprogrammers@gmail.comlesson9fibonacciseriesandmore1
http://sites.google.com/feeds/content/site/primaryprogrammers/33977724457545146592018-12-21T16:00:18.180Z2018-12-21T16:00:18.183Z2018-12-21T16:00:18.177ZLesson 8: 4 corners game and "What year were you born"? - Strings & Dates
 import time, random, datetimefor j in range(0,0): for i in range(1,11): print(i) time.sleep(1) corner = random.randint(1,4) print("If you are in corner", corner, "you are out")today = str(datetime.date.today())year = int(today + today + today + today)month = today + todayday = today + todaytoday = month + "/" + dayanswer = input("Were you born before or on " + today + "?: ")age = int(input("How old are you?: "))if answer == "yes": print("You were born in", year - age)else: print("You were born in", year - age - 1)
Attila Lengyelprimaryprogrammers@gmail.comlesson84cornersgameandwhatyearwereyouborn-stringsdates1
http://sites.google.com/feeds/content/site/primaryprogrammers/68193527981835452382018-12-14T16:01:24.700Z2018-12-14T16:01:24.703Z2018-12-14T16:01:24.695ZLesson 7: Timed & Graded Multiplication test
 import randomprint("Let's practice!")wins = 0losses = 0for i in range(0,5): coin = random.randint(0,1) side = "Head" if coin == 1: side = "Tail" guess = input("Head or Tail?").upper() if side.upper() == guess: print(side, "Ouch... :-( ... you won! ") wins = wins + 1 else: print(side, "Hurray... I won, you lost!!!") losses = losses + 1print("Wins:", wins, "Lost rounds:", losses)if wins > losses: print("Congrat! You won the game.")elif wins == losses: print("It's a tie!")else: print("Looser!!!")
http://sites.google.com/feeds/content/site/primaryprogrammers/37928791131771561472018-11-30T15:54:00.550Z2018-11-30T15:54:00.558Z2018-11-30T15:54:00.542ZLesson 5: Multiplication test with for loop
 print("Let's practice! What is 4 x 9?")answer = int(input())print("Your answer is", answer)if answer == 36: print("Correct!")else: print("Incorrect. Please practice math!")import randomprint("Are you ready for a test?")for i in range(1,11): a = random.randint(2,9) b = random.randint(2,9) print("Question", i,": What is", a, "x", b, "?") answer = int(input()) if answer == a * b: print("Correct!") else: print("Incorrect! The answer is", a * b)
Attila Lengyelprimaryprogrammers@gmail.comlesson5multiplicationtestwithforloop1
http://sites.google.com/feeds/content/site/primaryprogrammers/66735901427654542362018-11-16T16:01:31.389Z2018-11-16T16:01:31.399Z2018-11-16T16:01:31.380ZLesson 4: Control Flow
 print("Control flow")a = int(input("Give me a number:"))if a < 10: print("The number is smaller then 10") print("This is block 1")elif a == 10: print("The number is 10") print("This is block 2")else: print("The number is greater then 10") print("This is block 3")print ("This is the main flow")b = int(input("Give me a second number:"))op = input("Give me an operation:")if op == "+": print(a, "+", b, "=", a+b)elif op == "-": print(a, "-", b, "=", a-b)elif op == "*": print(a, "*", b, "=", a*b)elif op == "/": print(a, "/", b, "=", a/b)
Attila Lengyelprimaryprogrammers@gmail.comlesson4controlflow1
http://sites.google.com/feeds/content/site/primaryprogrammers/27450562535400033572018-11-09T15:58:56.460Z2018-11-09T15:58:56.466Z2018-11-09T15:58:56.455Z2018-19 Lesson 3: Strings, Integers and Float
 print("Hello World!!!")first_name = input("What is your name?")print("Hello", first_name, "How are you?")first_name = "Test"print("Hello", first_name, "How are you?")print("I can do math!")a = int(input("Give me a number:"))b = int(input("Give me a second number:"))print("The sum is", a + b)print("The difference is", a - b)print("The product is", a * b)print("The quotient is", a / b)print("a on the power of b", a ** b)a = a / bprint(a)import mathc = float(input("Give me c:"))d = float(input("Give me d:"))print("The sum is", c + d)print("The difference is", c - d)print("The product is", c * d)print("The quotient is", c / d)print("a on the power of b", c ** d)print("Square root of c", math.sqrt(c))print("Square root of d", math.sqrt(d))
Attila Lengyelprimaryprogrammers@gmail.com2018-19lesson3stringsintegersandfloat1
http://sites.google.com/feeds/content/site/primaryprogrammers/57774703331089864912018-10-12T14:59:38.897Z2018-11-07T16:05:14.245Z2018-11-07T16:05:10.503Z2018-19 Lesson 2: Cooking eggs
 print("Let's fry eggs!")num_peo = input("How many people will you serve?")print("Really?", int(num_peo), "people?")eggs_per = input("How many eggs per person?")total_eggs = int(num_peo) * int(eggs_per)print("Get", total_eggs, "eggs from the fridge!")
Attila Lengyelprimaryprogrammers@gmail.com2018-19lesson1cookingeggs2
 riddle = "hVObYomcioTcfoZSOfbWbUodfcUfOaaWbU"abc = "abcdefghijklmnopqrstuvwxyz !@#\$%^&*()_+:?> length - 1: y = y % length  return abc[y]def crypt(text, password, x):  key = getkey(password)  encryptedtext = ""  for c in text:    encryptedtext += shift(c, x * key)  return encryptedtext  def crack(text, num, x):  encryptedtext = ""  for c in text:    encryptedtext += shift(c, x * num)  return encryptedtext  text = input("Give me a text:")password = input("Give me a password:")secretmsg = crypt(text,password, 1)print(secretmsg)print(crypt(secretmsg, password, -1))riddle = input("Give me a text to crack:")for x in range(0, len(abc)):  input()  print(str(x) + ": " + crack(riddle, x, 1))
Attila Lengyelprimaryprogrammers@gmail.comlesson26riddle3
http://sites.google.com/feeds/content/site/primaryprogrammers/68477695491260980202018-05-10T15:03:27.571Z2018-05-11T15:00:08.500Z2018-05-11T15:00:06.276ZLesson 25: Simple encryption
 abc = "abcdefghijklmnopqrstuvwxyz !@#\$%^&*()_+:?> length - 1: y = y % length  return abc[y]def crypt(text, password, x):  key = getkey(password)  encryptedtext = ""  for c in text:    encryptedtext += shift(c, x * key)  return encryptedtext  text = input("Give me a text:")password = input("Give me a password:")secretmsg = crypt(text,password, 1)print(secretmsg)print(crypt(secretmsg, password, -1))
Attila Lengyelprimaryprogrammers@gmail.comlesson25simpleencryption2
http://sites.google.com/feeds/content/site/primaryprogrammers/47534828306039793412018-05-03T15:02:34.379Z2018-05-03T15:03:21.088Z2018-05-03T15:03:18.200ZLesson 24: Morse code
 import morsedict as mtext = input("Give me a text:")morsecode = ""for c in text:  morsecode += m.morsetab[c] + " "  print(morsecode)morsetab2 = {}for key,val in m.morsetab.items():  morsetab2[val] = keymorsecode = input("Give me morse:") t = ""for c in morsecode:  if c == " ":    print(morsetab2[t])    t=""  else:    t += c
Attila Lengyelprimaryprogrammers@gmail.comlesson23morsecode2
http://sites.google.com/feeds/content/site/primaryprogrammers/34842754279390845262018-04-19T15:02:53.719Z2018-04-19T15:02:53.741Z2018-04-19T15:02:53.695ZLesson 23: Playing with timers
 from datetime import datetimeimport time, mathfor x in range(0,3):  print(datetime.now())  time.sleep(1)def sectimer(seconds):  secperday = 60 * 60 * 24  days = math.floor(seconds / secperday)  seconds = seconds - days * secperday  secperhour = 60 * 60  hours = math.floor(seconds / secperhour)  seconds = seconds - hours * secperhour  secpermin = 60  minutes = math.floor(seconds / secpermin)  seconds = seconds - minutes * secpermin    strtime = ""  if days < 10: strtime += "0"  strtime += str(days) + ":"  if hours < 10: strtime += "0"  strtime += str(hours) + ":"  if minutes < 10: strtime += "0"  strtime += str(minutes) + ":"  if seconds < 10: strtime += "0"  strtime += str(seconds)    return strtime  start = datetime.now()counter = 0for x in range(0, 30):  print(sectimer(counter))  time.sleep(1)  counter += 1end = datetime.now()print (end - start)
Attila Lengyelprimaryprogrammers@gmail.comlesson23playingwithtimers1
http://sites.google.com/feeds/content/site/primaryprogrammers/8493687318781929592018-04-12T05:09:55.122Z2018-04-12T15:00:27.157Z2018-04-12T15:00:23.737ZLesson 22: Working with dates and converter between Fahrenheit and Celsius
 from datetime import datetimenow = datetime.now()print(now)mm = str(now.month)print(mm)dd = str(now.day)print(mm + "/" + dd)yyyy = str(now.year)print(mm + "/" + dd + "/" + yyyy)hour = str(now.hour)print(mm + "/" + dd + "/" + yyyy + " " + hour)mi = str(now.minute)print(mm + "/" + dd + "/" + yyyy + " " + hour + ":" + mi)ss = str(now.second)print(mm + "/" + dd + "/" + yyyy + " " + hour + ":" + mi + ":" + ss)import geocoderg = geocoder.ip('me')print(g.latlng)Celsius = float(input("Celsius:"))Fahrenheit = 9/5 * Celsius + 32print(Fahrenheit, "Fahrenheit")Fahrenheit = float(input("Fahrenheit:"))Celsius = (Fahrenheit - 32)*5/9print(Celsius, "C")
Attila Lengyelprimaryprogrammers@gmail.comlesson22workingwithdatesandconverterbetweenfahrenheitandcelsius2