简体   繁体   中英

in python, how do you put a user's input into a pre-exsitsing list variable

full section of code ex. here:

first, second, third, last =(input("test ")).split()
print("{0:s}{1:s}{2:s}{3:s}".format(last, third, second, first)))

User_guess=[0,0,0,0]
print(first)

User_guess.append[0]=first

this code tells the user to input a sentence and print it out backwards. (while splitting each word)

first, second, third, last =(input("test ")).split()
print("{0:s}{1:s}{2:s}{3:s}".format(last, third, second, first)))

User_guess=[0,0,0,0]
print(first)

User_guess.append[0]=first

this is the part where the problem occurs :line 13 in my prog. window...

User_guess.append[0]=first

. . . (i am VERY tired and have no idea what to fix) . . fYi, the variable User_guess links to a diffenrent part of the code that is affected by this. BUT the other part does NOT effect this.

User_guess is already a list of 4 elements so no need to use append() . Use User_guess[0]=first to store the variable first into 0'th element of User_guess list.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM