Python カテゴリーアーカイブ

Project Euler Problem 3
2010年07月21日 at 23時37分 Project Euler | Python

Problem 3

原文

The prime factors of 13195 are 5, 7, 13 and 29.

What is the largest prime factor of the number 600851475143 ?

続きを読む

Project Euler Problem 2
2010年06月10日 at 20時47分 Project Euler | Python

Problem 2

原文

Each new term in the Fibonacci sequence is generated by adding the previous two terms. By starting with 1 and 2, the first 10 terms will be:

1, 2, 3, 5, 8, 13, 21, 34, 55, 89, …

Find the sum of all the even-valued terms in the sequence which do not exceed four million.

続きを読む

Project Euler Probrem 1
2010年06月08日 at 22時55分 Project Euler | Python


Project Euler というものに挑戦していきます。
概要は以下。
http://projecteuler.net/
http://odz.sakura.ne.jp/projecteuler/index.php?Project%20Euler(日本語)
続きを読む

Python備忘録11
2010年05月30日 at 1時55分 Python | Python備忘録

リスト

リストの操作。

L = [1, 2, 3, 4, 5]
print "First", L
L.append(10)
print "Second", L
L.remove(10)
print "Third", L

実行結果↓
First [1, 2, 3, 4, 5]
Second [1, 2, 3, 4, 5, 10]
Third [1, 2, 3, 4, 5]

続きを読む

Python備忘録10
2010年05月25日 at 21時39分 Python | Python備忘録

widgets

実際の記法を少しずつ確認。

wx003.py

import wx   #wxをインポート

class MyApp(wx.App):   #メインのクラスを生成
	def OnInit(self):   #初期設定の関数を定義
		Frm = wx.Frame(None, -1, "Hello wxPython")   #メインウィンドウを作成
		Frm.Show()   #メインウィンドウを実際に表示
		Btn01 = wx.Button(Frm, -1, "Btn01")   #ボタンを作成
		return 1   #初期設定関数の返値。気にする必要はないが必ず書く

app = MyApp()   #メインのクラスからオブジェクトを作る
app.MainLoop()   #動作させ、待機

[3] class MyApp(wx.App):
括弧内は実際にwxPythonで動作させるアプリケーションの種類。
現在のところwx.Appかwx.PySimpleAppを利用。
後者はエラーを端末にはき出す。

[5] Frm = wx.Frame(None, -1, “Hello wxPython”)
メインのウィンドウをFrmという名前で作成。
記法: オブジェクト名 = ウィジェット(親ウィジェット, ID, …..)
括弧の中は状況に応じて。
IDは-1にすると勝手に設定してくれます
この場合はメインのフレームなので親はなし→None

Python備忘録9
2010年05月24日 at 23時54分 Python | Python備忘録

wxPython-xrcedの利用

xrcedでGUIフレームを作り、メインのプログラムは別に書く。

Python備忘録8
2010年05月24日 at 23時44分 Python | Python備忘録

wxPython

Tkinterに変わるGUI Toolkit。
Tkinterは重くてよくないらしい。
http://www.wxpython.org/
ドキュメント、サンプルコード類もインストールするといいよ。

Python備忘録7
2010年03月04日 at 21時14分 Python | Python備忘録

pass — 何もしない

文法上何かプログラムを書かなければいけないが、することがないとき
たとえば、

if i==5:
     <strong>pass</strong>
else:
     print i

のように使えます。

Python備忘録6
2010年03月04日 at 18時06分 Python | Python備忘録

for文

for 適当な変数 in 何かしらの範囲指定:
     実行文

一般的な構文としては

for i in range(10):
     print i

のような形。
↓実行すると

0
1
2
3
4
5
6
7
8
9

続きを読む

Python備忘録5
2010年03月04日 at 0時08分 Python | Python備忘録

while文 — 条件に合っている間繰り返す

while 条件文:
     実行文

続きを読む

Get Adobe Flash playerPlugin by wpburn.com wordpress themes