D
D
ddgryaz2020-10-31 19:31:25
Python
ddgryaz, 2020-10-31 19:31:25

What is the difference between handwritten code and pasted code?

I welcome everyone! I immediately apologize for a possibly stupid question, but I do not understand what is going wrong.

And so, watching a couple of videos on YouTube, I write code by analogy as the author of the video does, in the intermediate result he launches the program and it works in his video, but mine throws an error.

Having opened a new Python script in the second window, I pasted part of his code, which he will post on github - as a result, it works. And mine is exactly the same, which I wrote with my hands, throws an error.
What's the real deal?

My code:
import pygame as pg
import pymunk.pygame_util
pymunk.pygame_util.positive_y_is_up = False

DISP = WIDTH, HEIGHT = 600, 600
FPS = 60

pg.init()
display = pg.display.set_mode(DISP)
clock = pg.time.Clock()
draw_options = pymunk.pygame_util.DrawOptions(display)

# Пространство
space = pymunk.Space
space.gravity = 0, 2000

# Динамический объект мяч
ball_mass = 1
ball_radius = 20
ball_moment = pymunk.moment_for_circle(ball_mass, 0, ball_radius)
ball_body = pymunk.Body(ball_mass, ball_moment)
ball_body.position = WIDTH // 2, 0
ball_snape = pymunk.Circle(ball_body, ball_radius)
space.add(ball_body, ball_snape)

while True:
    display.fill(pg.Color('black'))

    for i in pg.event.get():
        if i.type == pg.QUIT:
            exit()

    space.step(1 / FPS)
    space.debug_draw(draw_options)


    pg.display.flip()
    clock.tick(FPS)

Code copied from github:
import pygame as pg
import pymunk.pygame_util
pymunk.pygame_util.positive_y_is_up = False

RES = WIDTH, HEIGHT = 1200, 1000
FPS = 60

pg.init()
surface = pg.display.set_mode(RES)
clock = pg.time.Clock()
draw_options = pymunk.pygame_util.DrawOptions(surface)

space = pymunk.Space()
space.gravity = 0, 8000


ball_mass = 1
ball_radius = 20
ball_moment = pymunk.moment_for_circle(ball_mass, 0, ball_radius)
ball_body = pymunk.Body(ball_mass, ball_moment)
ball_body.position = WIDTH // 2, 0
ball_snape = pymunk.Circle(ball_body, ball_radius)
space.add(ball_body, ball_snape)


while True:
    surface.fill(pg.Color('black'))

    for i in pg.event.get():
        if i.type == pg.QUIT:
            exit()

    space.step(1 / FPS)
    space.debug_draw(draw_options)


    pg.display.flip()
    clock.tick(FPS)


Screenshot from PyCharm showing number of errors

5f9d9083b21a1013154062.png

The error that PyCharm throws with my code
5f9d90b2b7586733029911.png

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dr. Bacon, 2020-10-31
@ddgryaz

diff

N
Nikita, 2020-10-31
@VinchesTer312

Try creating a new project, and copy your code (that you wrote by hand) and paste it into the new project

D
ddgryaz, 2020-10-31
@ddgryaz

I made a mistake on line 14. And checking 100 times - did not notice her. As soon as I posted the question, I immediately noticed :( The
question was actually resolved. I apologize and good mood to everyone! ;)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question