全部原始碼:http://pastie.org/pastes/1597813
2011年2月23日 星期三
2011年2月8日 星期二
2011年1月31日 星期一
[Python]檔案讀寫
程式碼
輸出結果
參考網站:ZHPY
# -*- coding: UTF-8 -*-
'''
Python ver:3.1.3
Filename: usefile_1.py
Author: Rex Li
Data:2011-01-31
'''
print (__doc__)
p = '''\
這是一個文字檔建立的程式
試著去使用他吧
''' #斜線使第一行不空白
fileopen = open('ppp3.txt','w') #開啟檔案,w沒有該檔案就新增
fileopen.write(p) #寫入 p的內容
fileopen.close() #關閉檔案
fileopen = open('ppp3.txt')
while True:
line = fileopen.readline() #讀寫一行
if len(line) ==0: #檢視是否有字串
break
print (line)
fileopen.close()
輸出結果
Python ver:3.1.3 Filename: usefile_1.py Author: Rex Li Data:2011-01-31 這是一個文字檔建立的程式 試著去使用他吧簡易讀取
for i in open('ppp.txt'):
print (i)
參考網站:ZHPY
2011年1月29日 星期六
2011年1月27日 星期四
[python]list and can't print big5 list(is oK)
程式碼
# -*- coding: utf-8 -*-
# File name list.py
str = ['蘋果', '香蕉', '火龍果', '橘子']
print '我有', len(str),'樣東西在清單理'
for item in str:
print item,
print
print '我也需要買米'
str.append('米')
print '我的新的清單','[',
for item in str:
print item,
print ']'
print '排序我的清單','[',
for item in str:
print item,
print ']'
str.sort()
print '排序好的清單','[',
for item in str:
print item,
print ']'
print '我第一個要買的',str[0]
olditem = str[0]
del str[0]
print '我買了',olditem
print'我的現在清單','[',
for item in str:
print item,
print ']'
2011年1月24日 星期一
[python]猜數字
程式碼
# -*- coding: utf8 -*-
'''
File name guess.py
REX li
2011-01-24
'''
number = 65
running = True
while running:#當running為 Ture 會執行下 程式
guess = int(raw_input('請輸入一個整數(0-100):'))
if guess == number:
print '恭喜!!你猜對了'
print '但沒有獎品= ='
running = False #如果為 False 會使程式終止
elif guess < number:
print '數字在大一點'
else:
print '數字在小一點'
else:
print '遊戲結束'
輸出結果
請輸入一個整數(0-100):55 數字在大一點 請輸入一個整數(0-100):66 數字在小一點 請輸入一個整數(0-100):65 恭喜!!你猜對了 但沒有獎品= = 遊戲結束參考網頁:http://code.google.com/p/zhpy/wiki/ControlFlow
訂閱:
文章 (Atom)
