I've been trying to make a function that uses a number previously determined from another function (which I have that part of the code working) and asks the user to give an amount of names equal to the number previously determined. Here's the code:
def getNames(myNumOfTypes):
print("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~")
print("Now, enter all the names of the people getting a type:")
names = []
for i in range(0, myNumOfTypes):
name = input("-")
names.append(name)
return names[i]
Later, when I print the names list, it's only a list of the last input I entered... I never really learned for loops and lists, and now I'm trying to use both and it's rough. for reference, myNumOfTypes was a variable I used earlier, but because the numbers have to be the same I just recycled it.
您在最后一行添加了一个[i]
来获取特定索引的值,您需要将其删除以使最后一行变为:
return names
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.