[問題] 一題 有沒有第二種解法已刪文
這是我這學期上通識的題目
輸入整數Z,除非輸入5,否則繼續輸入。當5出現時,表示輸入完成。(最後一次輸入的5
也算在內,將陸續資料以空格分隔寫入檔案a.txt。此時再由螢幕輸入m、n 然後以
一串列b來讀取檔案中第m~n的內容1.3將b串列提供給自行設計的函數g並由函數g處理
輸出這段串列中的內容、加總、最大值、最小值。
我寫出來的如下
def g(b):
print('\nb:\,b)
print('sum;',sum(b))
print('max;',max(b))
print('min;',min(b))
f3=open('e:\\a.txt',w')
a=input('pls input a, until a=5:')
f3.write(a)
while eval(a)!=5
a=input('pls input a, until a=5 :')
f3.write(''+a)
f3.close()
f2=open('e:\\a.txt','r')
#d=str.split(f2.readlines()[0],'')
d=str.split(f2.readline(),'')
d=list(map(int,d))
#for i in range(len(d)):
# d[i]=eval(d[i])
f2.close()
k=len(d)
m=eval(input('\npls input m,where m<'+str(k)+':'))
n=eval(input('pls input n, where n <'+str(k)+':'))
if(m>n):m,n=n,m
b=d[m-1:n]
g(b)
#END
新手求救 老師給的作業要兩種做法
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 123.193.115.76 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/Python/M.1561022227.A.8B6.html
→
06/20 18:08,
6年前
, 1F
06/20 18:08, 1F
→
06/20 18:23,
6年前
, 2F
06/20 18:23, 2F
→
06/20 18:55,
6年前
, 3F
06/20 18:55, 3F
Python 近期熱門文章
PTT數位生活區 即時熱門文章