我試圖按順序返回用戶輸入單詞和數字的列表,但是當我運行模塊時,輸入單詞並輸入它的值而不是條款和值依次排列。嘗試按順序返回值和單詞列表
dictionary = []
value = []
addterm1 = raw_input("Enter a term you would like to add to the dictionary: ")
addterm2 = raw_input("Enter a term you would like to add to the dictionary: ")
addterm3 = raw_input("Enter a term you would like to add to the dictionary: ")
addvalue1 = float(raw_input("Enter a number you would like to add to the set of values: "))
addvalue2 = float(raw_input("Enter a number you would like to add to the set of values: "))
addvalue3 = float(raw_input("Enter a number you would like to add to the set of values: "))
dictionary.append(addterm1)
dictionary.append(addterm2)
dictionary.append(addterm3)
value.append(addvalue1)
value.append(addvalue2)
value.append(addvalue3)
def reverseLookup(dictionary, value):
print dictionary.sort()
print value.sort()
if __name__ == '__main__':
reverseLookup(dictionary, value)
你可以做這麼多與循環,例如短對於範圍(3)中的_:value.append(float(raw_input(...))'。在連續的行上重複相同的字符串是一個死牌。 – jonrsharpe