According to the plan of last week, start learning pygame today.
1. hello world Program of pygame version.
Code:
[Python]#! /Usr/bin/python#-*-Coding: UTF-8 -*-Import sys# Import the pygame module. Line 4 is used to simplify your input. For example, you do not need to add the pygame Module name before the event.Import pygameFrom pygame. locals import *Def hello_w
not complete, only 20000 + data)While 1: list = [] s =raw_input (' Please enter idiom: ') ns = S.decode (' GBK ') [-1:] try: For I in Chengyu.values (): ni = i[:1] if ns = = ni: list.append (i) print U ' solitaire: ', Len (list), Random.choice (list) except: print U ' Solitaire: It's under the loss ': No optimized processing, no judgment on whether the user entered the correct idiom.The program is relatively simple, the ma
Python game engine development (7): drawing vector Graphs
Today, we will draw a vector image.Graphics class
First, createGraphicsClass is used to create vector graphics:
Class Graphics (DisplayObject): def _ init _ (self): super (Graphics, self ). _ init _ () # self. _ drawingList = [] # used to store the current graphic data self. _ currentGraphics = None
Since our window interface is constantly being clea
Python game engine development: TextField text
TextField
Anyone who has used flash knows that this class is not only used to display text, but also used to display input boxes. I will only implement some basic and practical functions here, and it will take some time to expand. Like the previous chapter,TextFieldIs a display object inherited fromDisplayObject. The following
During the Christmas period, I looked at the python for loop. Just practice, on a whim, wrote a small program of the Christmas tree. For Gentlemen a happy!The following code is attached:#coding: Utf-8importsysdefchristmas (h):print ' \033[1;36;40m\t Welcome to!\n is making your own Christmas tree, please wait! \033[0m ' print ' \033[1;32;40m ' #print ' t ', foriinrange (1,h+1): print ' t ',forj Inrange (0,
10
30
-5 (P)
This problem is two-dimensional dynamic programming, the key is the tectonic transfer equation. The first requirement for each step of the move process Knight HP is greater than 0, followed by the minimum requirements.
So we can construct a matrix DP of MXN to record the moving process. Its transfer equation is Dp[row][col]=max (1,min (dp[row+1][col],dp[row][col+1])-dungeon[row][col]) space complexity and time complexity are O (MN)
This was
sauce purple mode to save a lot of judgment:
wdict = {} for word in words: try: wdict[word] += 1 except KeyError: wdict[word] = 1
Reduce the number of function calls as much as possible and use an internal loop instead. For example, do not use soy sauce:
x = 0 def doit1(i): global x x = x + i list = range(100000) t = time.time() for i in list: doit1(i)
Soy Sauce purple:
x = 0 def doit2(list): global x for i in list: x = x + i list = range(100000) t = time.time() doit2(list)
Third move:
Python captures special code record and python special code record
Background:
When I was a child, there was a kind of game, two protagonists: Bai XX and Zeng XX. Each family gave them up like a living Bodhisattva for them to eat and wear.
The business owner has made great e
readable. Of course, theoretically x>yis add (x, y) generally faster than a+b? This I have doubts, experiment a bit, first add can not directly use, to import operator, second, my experimental results indicate that add (x, y) is not a+b fast, let alone also sacrifice readability.While 1 is really a little bit faster than while True. Two experiments were done, about 15% faster.Five strokes: No snake wins with snakes: Performance outside the
', autospec=true) def test_post_message (self, mock_put_object): SF = Simple_facebook. Simplefacebook ("Fake OAuth token") sf.post_message ("Hello world!") # Verify Mock_put_object.assert_called_with (message= "Hello world!")
As far as we can see, it's really easy to start writing smarter tests in Python using mock-up.Summarize
Python's mock library, which is used to confuse ideas, is a game
Summary of 80 typical Python documents (tutorials + source code + tools)-download directory. Hello everyone, the 51cto download center collects 80 Python documents based on the popularity and praise of the materials, share it with Python developers. The content includes 1 Python
second trick: a snake Zen: just a trick
When I first started touching python, one of my seniors told me that Python had a great idea, and it wanted everyone with it to write exactly the same program. Python's Zen is a cloud:
There should be one--and preferably only one--obvious to do it
So the Python professional Z
=message)
Here is our test case, which checks that I sent the message, but does not actually send this message (to Facebook):
Import facebookimport simple_facebookimport mockimport unittestclass simplefacebooktestcase (unittest. TestCase):
@mock. Patch.object (Facebook). Graphapi, ' Put_object ', Autospec=true
def test_post_message (self, mock_put_object):
SF = Simple_facebook. Simplefacebook ("Fake OAuth token")
sf.post_message ("Hello world!") # Verify
Mock
100 lines of python code to implement a one-hop Helper Program and 100 lines of python
Preface
I will share with you the Helper Program for the "hop-on" game written in python this afternoon. In the past, I was preparing to use Raspberry Pi to manipulate a "mechanical finger
200 lines of python code for 2048 games, python2048
Create a game file 2048.py
First, import the required package:
import cursesfrom random import randrange, choicefrom collections import defaultdict
Main Logic
User behavior
All valid inputs can be converted to "Up, down, left, right, game reset, and exit", expressed i
German English! Our main business scope is to do programming big homework, curriculum design and so on.Our Direction field: Window Programming numerical algorithm AI Artificial Intelligence financial statistical Metrology analysis Big Data network programming Web programming Communication Programming game Programming Multimedia Linux plug-in programming API image processing embedded/Microcontroller database programming console process and thread Netw
! Our main business scope is to do programming big homework, curriculum design and so on.Our Direction field: Window Programming numerical algorithm AI Artificial Intelligence financial statistical Metrology analysis Big Data network programming Web programming Communication Programming game Programming Multimedia Linux plug-in programming API image processing embedded/Microcontroller database programming console process and thread Network security as
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.