Welcome to TokyoEdtech's RU-vid channel! I am a middle and high school computer science teacher and I make computer programming tutorials, mostly in Python (and sometimes Java). My tutorials are mostly beginner-friendly and focus on making simple games, simple apps, and computer science principles.
Become a channel member and support more great coding content by clicking here: ru-vid.com/show-UC2vm-0XX5RkWCXWwtBZGOXgjoin
I came around as python beginner which already did some small project in pygame. This is actually great stuff to help me better practice arrays and understand logic of python. Thank you even after 9 years your YT video is helping dum dums like me.
My player is not showing up on the screen,only rarely it does import os import random import turtle turtle.fd(0) turtle.speed(0) turtle.bgcolor("black") turtle.ht() turtle.setundobuffer(1) turtle.tracer(1) delay = input('entter a key to end') class Sprite(turtle.Turtle): def __init__(self,spriteshape,color,startx,starty): turtle.Turtle.__init__(self,shape= spriteshape) self.speed(0) self.penup() self.color(color) self.fd(0) self.goto(startx,starty) self.speed = 1 def move(self): self.fd(self.speed) class Player(Sprite): def __init__(self,spriteshape,color,startx,starty): Sprite.__init__(self,shape= spriteshape,color=color,startx=startx,starty=starty) self.speed = 4 self.lives = 3 player = Player( spriteshape="triangle", color="white", startx= 0, starty= 0 ) while True: player.move()
@@sangeetaanand1 Hi! You don't need the delay line - delete it. Also, you've copied the class Player code wrong. See the correct code here: ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-_tnYXAJGIvU.htmlsi=eOThfZg4sOMjcnxd&t=305
Hi! I dont know if you are still replying to comments on this video, but when I type Head.direction “Direction” Isnt a thing, I would appreciate if you could help me, thank you!
I'm not able to go into replit, and I didn't go anywhere as the signup feature took me to a blank page, I did go to your : Download the code here and I'm not sure what to do there man
@@mikayelalikhanyan1587 Sorry, I can't help with repl.it. You can try a different browser to see if they helps. Otherwise contact their customer support. The link takes you to s page with the programs I wrote in the video. You can read them or download them or copy and paste into repl once you get out working.
You are correct - you can use whatever casing you want to use; the compiler/interpreter does not care. However, each language has its own casing convention that you should follow - especially when working with others or when planning to share your code. In the case of Python it is found in PEP8: peps.python.org/pep-0008/#prescriptive-naming-conventions In the case of Java it is found here: www.oracle.com/java/technologies/javase/codeconventions-namingconventions.html
Hiya - This is great - I love seeing people take an idea and add their own personal touch. You have two problems. 1. You have score sitting there by itself. This isn't a real problem, but I'd get rid of it. 2. You have: if score > high_score: score = high_score It should be: if score > high_score: high_score = score If you think about it a bit it should make sense. Keep on codin'!
Here is my code import turtle import time import random delay = 0.1 # Set up the screen wn = turtle.Screen() wn.title("Snake Game by @tokyoEdtech ") wn.bgcolor("green") wn.setup(width=600, height=600) wn.tracer(0) # Turns off the screen updates # Snake head head = turtle.Turtle() head.speed(0.2) head.shape("square") head.color("black") head.penup() head.goto(0,0) head.direction = "stop" # Snake food food = turtle.Turtle() food.speed(0.2) food.shape("circle") food.color("red") food.penup() food.goto(0,100) segments = [] # Functions def go_up(): head.direction = "up" def go_down(): head.direction = "down" def go_left(): head.direction = "left" def go_right(): head.direction = "right" def move(): if head.direction == "up": y = head.ycor() head.sety(y + 20) if head.direction == "down": y = head.ycor() head.sety(y - 20) if head.direction == "left": x = head.xcor() head.setx(x - 20) if head.direction == "right": x = head.xcor() head.setx(x + 20) # Keyboard bindings wn.listen() wn.onkeypress(go_up, "w") wn.onkeypress(go_down, "s") wn.onkeypress(go_left, "a") wn.onkeypress(go_right, "d") # Main game loop while True: wn.update() # Check for a collision with the border if head.xcor()>290 or head.xcor()<-290 or head.ycor()>290 or head.ycor()<-290: time.sleep(1) head.goto(0, 0) head.direction = "stop" # Hide the segments for segment in segments: segment.goto(1000, 1000) # Clear the segments list segments = () # Check for a collision with the food if head.distance(food) < 20: # Move the food to a random spot x = random.randint(-290, 290) y = random.randint(-290, 290) food.goto(x,y) # Add a segment new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("grey") new_segment.penup() segments.append(new_segment) # Move the end segments first in reverse order for index in range(len(segments)-1, 0, -1): x = segments[index-1].xcor() y = segments[index-1].ycor() segments[index].goto(x, y) # Move segment 0 to where the head is if len(segments) > 0: x = head.xcor() y = head.ycor() segments[0].goto(x,y) move() # Check for head collision with the body segments for segment in segments: if segment.distance(head) <20: time.sleep(1) head.goto(0,0) head.direction = "stop" # Hide the segments for segment in segments: segment.goto(1000, 1000) # Clear the segments list segments = () time.sleep(delay) wn.mainloop()
@@eillieel8870 Hiya, At two parts of your program, you have segments = () It should be: segments = [] There are also some indentation errors you'll need to fix.
Hiya. There is a difference between = and == You have: def go_up(): head.direction == "up" It should be: def go_up(): head.direction = "up" When comparing you use ==, but when assigning you use =
excuse me Mr. TokyoEdtech well that border that you are talking about does not appear to be working on my PC because I'm using Python 3.12.5? or something else?
@@Miabukk You have to explain a little better - the program is not working at all, not just the border. I got the following error: Traceback (most recent call last): File "/Users/teacher/Desktop/help.py", line 195, in <module> game. draw_border() ^^^^^^^^^^^^^^^^^ AttributeError: 'Game' object has no attribute 'draw_border' ANyhoo, I tried fixing it, but there were too many mistakes - some were incorrect indentation, others you just copied wrong. If you follow along with the video, you should be testing each part as you add it so you don't end up with so many problems at once. There is a link in the description to the correct code, I'd suggest starting there and moving forward carefully.
File "/data/user/0/ru.iiec.pydroid3/files/temp_iiec_codefile.py", line 33 move( ) ^ IndentationError: unindent does not match any outer indentation level
For anyone who may have had trouble getting set up I figured I might just write what happened to me and how I fixed it for reference. I am using Mac OS Sonoma with an intel processor. I already had homebrew installed on my laptop along with python 3.9.6. When I first ran the code in IDE, VS Code that is displayed at 2:38 I was only seeing a small grey box. It took a while but I trouble shot this by using homebrew to uninstall python and then reinstall. (I did not uninstall the Mac OS default Python file). Then I did the same with VS code. I also installed pyenv and tcl-tk with homebrew(honestly not sure if this helped with anything.) After doing this I made an alias in my ~/.zshrc file to have the command python point to python3 in my usr/local/bin so that whenever I use python in the terminal it now points to the newer version (3.12.5) instead of the system default I found that solution on stackoverlfow.com Lastly in VS Code I had to choose the version of python I wanted to use which is done down at the bottom right hand corner next to the interpreter selector. Using 3.9.6 was still an option but this version didn't work at all and threw an error message about a deprecating package and didn't even let me hit enter to exit, I did change delay = raw_input() to just input() and so using 3.12 works perfectly so far no problems. I hope this is clear enough to help someone (:
I will seriously pray for your health. I found this code in geeksforgeeks but i didn't get it. I scaned phyton books for 2 days but it didn't work for me. I appreciate a lot. You have a detailed and descriptive explanation. I will definetely follow your videos.💝💝💝🥰
@@DOGPERSON4 I think the code is probably fine - this tutorial is still surprisingly popular. However, compared to my other videos, it is not as beginner friendly. If you want to share your code and error messages, I can take a look and point you in the right direction.
Sorry, but when I hit the border, there is an error, my code import turtle import time import random delay = 0.1 #Set up the screen windows = turtle.Screen() windows.title("If your score is 1,000 ") windows.bgcolor("green") windows.setup(width=600, height=600) windows.tracer(0) #Snake Head Head = turtle.Turtle() Head.speed(0) Head.shape("square") Head.color("yellow") Head.penup() Head. goto(0,0) Head.direction = "stop" #Snake Food Food = turtle.Turtle() Food.speed(0) Food.shape("circle") Food.color("red") Food.penup() Food. goto(0,100) segments = [] #Functions def move(): if Head.direction == "up": y = Head.ycor() Head.sety(y + 20) if Head.direction == "down": y = Head.ycor() Head.sety(y - 20) if Head.direction == "left": x = Head.xcor() Head.setx(x - 20) if Head.direction == "right": x = Head.xcor() Head.setx(x + 20) def go_up(): Head.direction = "up" def go_down(): Head.direction = "down" def go_right(): Head.direction = "right" def go_left(): Head.direction = "left" #Keyboard Bindings windows.listen() windows.onkeypress(go_up, "Up") windows.onkeypress(go_down, "Down") windows.onkeypress(go_left, "Left") windows.onkeypress(go_right, "Right") #Main Game Loop while True: windows.update() #Check for a collision with the border if Head.xcor() > 290 or Head.xcor() < -290 or Head.ycor() > 290 or Head.ycor() < -290: time.sleep(1) Head.goto(0, 0) Head.direction = "stop" #Hide the segments for segments in segments: segments.goto(1000, 1000) #Clear the segments list segments.clear() if Head.distance(Food) < 20: #Move the food to a random spot x = random.randint(-290, 290) y = random.randint(-290, 290) Food.goto(x, y) #make a new segment new_segment = turtle.Turtle() new_segment.speed(0) new_segment.shape("square") new_segment.color("dark grey") new_segment.penup() segments.append(new_segment) #Move the end segments first in reverse order for index in range(len(segments)-1, 0, -1): x = segments[index-1].xcor() y = segments[index-1].ycor() segments[index].goto(x, y) #Move segment 0 to where the head is if len(segments) > 0: x = Head.xcor() y = Head.ycor() segments[0].goto(x, y) move() time.sleep(delay) windows.mainloop()
I'm getting started in teaching myself to code. At the moment I'm using Python. Could you guys maybe help me out in figuring out what you call the program that he is using to code and if it's free to use. It might come off as a stupid question for some of you experienced coders, but I am just starting out and I am very much interested in giving this a go. Thank you very much!
@@heinzandberg2716 Everybody has to start somewhere. Try this video first : ru-vid.com/video/%D0%B2%D0%B8%D0%B4%D0%B5%D0%BE-Yu-6RDCO2BY.htmlsi=tk4pMOmLvUJPo7lm