基本上有三個問題需要在這裏解決。
從用戶收集列表。
生成列表中成對組合的詳盡列表。
收集來自用戶的每一對偏好。
使用每個配對的偏好對列表施加一個順序。
前3個問題相當簡單,但第4個問題是一個數學討論和發表的主題。
以下是python3的裸骨頭腳本。
#!/bin/python3
# Part 1 get the list from the user.
items = []
item = "..."
while(item!=""):
item = input("enter item name or type enter to continue:")
if(item!=""):
items.append(item)
# Part 2 make combinations from list
def combinations(aList):
done = []
result = []
for k in aList:
done.append(k)
for k2 in aList:
if not(k2 in done):
result.append((k,k2))
return(result)
toRank = combinations(items)
# Part 3 get rankings for combinations
preferences = {}
for k in toRank:
choice = "2"
while not(choice in ["0","1"]):
choice = input("0:"+k[0]+"\t"+"1:"+k[1]+"\n")
preferences[k] = choice
# Part 4 rank list based on rankings
# This part is not straight forward but for the purposes of the example
# we will simply put things in order based on how many times they were
# chosen in a head on head comparison.
wins = {k:0 for k in items}
for k in preferences:
wins[k[int(preferences[k])]]+=1
from operator import itemgetter
rankedList = sorted(wins.items(), key=itemgetter(1))
rankedList.reverse()
#Print The final result
resultText = ""
for k in rankedList:
resultText+=str(k)+"\n"
with open("restultFile.txt","w") as outFile:
outFile.write(resultText[:-1])
這是最小可行產品。它是完全裸露的骨頭,但它的存在允許早期用戶確定哪些規範應該納入下一代產品。編寫代碼就是定義可獲得的增量。從小處開始建立起來。
如果你有興趣學習編程,我會建議你首先制定你的第一個目標「hello world」(編寫一個程序,將文本「hello world」放在屏幕上),而提供的例子是在python3中現有的HTML經驗可能會讓JS成爲您開始學習的最佳語言。
編輯:輸出打印到文件「restultFile.txt」,而不是打印到終端。
任何您喜歡的語言?你是否嘗試做像Spotify這樣的事情? –
2000年初的html lol,所以沒有。不,我試圖讓它可以手動地單獨輸入每個項目,所以一旦你編譯了列表,它就開始運行比較。 – ECHtoplasm
hahahah,沒什麼好看的 –