Problem 3
原文
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
原文
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143 ?
原文
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 というものに挑戦していきます。
概要は以下。
http://projecteuler.net/
http://odz.sakura.ne.jp/projecteuler/index.php?Project%20Euler(日本語)
続きを読む
リストの操作。
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]
続きを読む
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
xrcedでGUIフレームを作り、メインのプログラムは別に書く。
Tkinterに変わるGUI Toolkit。
Tkinterは重くてよくないらしい。
http://www.wxpython.org/
ドキュメント、サンプルコード類もインストールするといいよ。
文法上何かプログラムを書かなければいけないが、することがないとき
たとえば、
if i==5:
<strong>pass</strong>
else:
print i
のように使えます。
for 適当な変数 in 何かしらの範囲指定:
実行文
一般的な構文としては
for i in range(10):
print i
のような形。
↓実行すると
0 1 2 3 4 5 6 7 8 9