Posts

Showing posts with the label Python3

How to Draw a Rectangle using Pygame

Image
What is Pygame? Pygame is a Python library designed to develop video games. Pygame adds functionality on top of the excellent SDL library. This allows you to create fully featured games and multimedia programs in the Python language. The Functions We Need! pygame.display.set_mode() : This function is used to initialize a surface for display. This function takes the size of the display as a parameter. pygame.display.flip() : This function is used to update the content of the entire display surface of the screen. pygame.draw.rect() : This function is used to draw a rectangle. It takes the surface, color, and pygame Rect object as an input parameter and draws a rectangle on the surface. Example 1:   Drawing a rectangle and filled it with blue color. from pygame.locals import * def main (): pygame.init() DISPLAY=pygame.display.set_mode(( 500 , 400 ) , 0 , 32 ) BLUE=( 0 , 0 , 255 ) pygame.draw.rect(DISPLAY , BLUE , ( 200 , 150 , 100 , 50 )) while True : ...

Rock, Paper, Scissor using Python 3

Image
  Rock, Paper, Scissor using Python  I’m guessing you’re learning Python because you want to write interactive programs, like video games. Well, today is your lucky day. You’re going to program your first Python game. Rock, Paper, Scissor  Open IDLE and create a new file, rps.py. Then enter the following:  __________________________________________________________________________________  from random import randint #create a list of play options t = [ "Rock" , "Paper" , "Scissors" ] #assign a random play to the computer computer = t [ randint ( 0 , 2 ) ] #set player to False player = False while player == False : #set player to True player = input ( "Rock, Paper, Scissors?" ) if player == computer : print ( "Tie!" ) elif player == "Rock" : if computer == "Paper" : print ( "You lose!" , computer , "covers...