2016-12-01 70 views
1
def randomLetters(): 
    numbers = [random.randint(0, 25), random.randint(0, 25)] 
    alphabet = 'abcdefghijklmnopqrstuvwxyz' 
    letters = [alphabet[numbers[0]], alphabet[numbers[1]]] 
    return letters 

letters = randomLetters() 
print(letters) 
print(letters[0]) 
user_input = input('Enter a word that begins with', "'" + letters[0] + "'", 'and ends with', "'" + letters[1] + "': ") 
new_user_input = user_input.lower() 

while (new_user_input[0] != letters[0]) and (new_user_input[len(new_user_input) - 1] != letters[1]): 
    print('Invalid input. Try again.') 
    new_user_input = input('Enter a word that begins with', "'" + letters[0] + "'", 'and ends with', "'" + letters[1] + "': ") 

的USER_INPUT變量輸入產生一個TypeError相關聯的USER_INPUT變量是此錯誤:輸入預期至多1個參數,得到4產生一個類型錯誤:輸入預期至多1個參數,得到4.從與強輸入

回答

0

input()只需要一個Arg和您所提供它4,,分離參數,也許你的意思+

new_user_input = input('Enter a word that begins with' + "'" + letters[0] + "'" + 
         'and ends with' + "'" + letters[1] + "': ") 

format()有助於構建這些字符串簡單:

new_user_input = input("Enter a word that begins with '{letters[0]}' and ends with '{letters[1]}': ".format(letters=letters)) 
相關問題