title: The character I created doesn't come back to the exact platform after a single trigger press on UP arrow key
body: <p>I am a Pygame beginner. I started to build a game on jumping dinosaur. The character I created doesn't come back to the exact platform after a single trigger press on UP arrow key. It lands slightly above the platform and its lands perfectly after 2,3 UP arrow presses.</p>
  
  <p>I am a complete beginner.</p>
  
  <pre><code>import pygame
  pygame.init()
  
  win = pygame.display.set_mode((500, 500))
  
  
  x = 20
  y = 400
  width = 30
  height = 45
  vel = 10
  black = (0,0,0)
  
  x1 = 20
  y1 = 30
  
  white = (255,255,255)
  
  
  run = True
  
  while run:
      pygame.time.delay(20)
      win.fill(black)
      for event in pygame.event.get():
          if event.type == pygame.QUIT:
              run = False
  
      keys = pygame.key.get_pressed()
  
      if keys[pygame.K_LEFT] and x&gt;=20:
          x -= vel
  
      if keys[pygame.K_RIGHT]and x&lt;=450:
          x += vel
  
      if keys[pygame.K_UP] and y&gt;=20:
          y -= vel
  
      if keys[pygame.K_DOWN] and y&lt;=390:
          y += vel
      #gravity
      else:
          if not keys[pygame.K_UP] and y &lt;= 400:
              y += 30
  
      pygame.draw.rect(win, (255, 0, 0), (x, y, width, height))
      pygame.draw.line(win,white,[0,472],[472,472],2)
      pygame.display.update()
      pygame.display.flip()
  pygame.quit()
  </code></pre>