0
我對遞減順序輸出從給定文件編號:在沒有內置函數
- 在列表中要求用戶輸入文件
- 檢查文件是否存在
- 店數(從文件)
- 列表的長度找到
- 和排序在沒有內置函數遞減順序
這是我到目前爲止有:
def main():
try:
file=open(input (str("Please enter the name of the file you wish to open:")),"r")
A= file.readlines()
print (A)
file.close
n=len(str(A))
print (n)
new_list=[]
for i in range (n):
for j in range (n-i):
if A(j-1) < A(j):
swap (A(j), A(j-1))
except IOError as e:
print("({})".format(e))
我不知道有什麼可以打印爲置換後。 (j-1)< A(j): TypeError:'list'對象不可調用「)
我該怎麼辦?
要使用'[]'而不是'()'來訪問列表的元素,但是什麼是'swap'? (看起來像你幾乎粘貼了一些僞代碼) –
http://docs.python.org/2/tutorial/introduction.html#lists – YXD