0
列表中刪除的東西所以我編寫了Python 3.5.2的清單。我的部分清單是通過在列表中鍵入事物的名稱來刪除列表中的某些東西的功能。我一直在想辦法去做,但還沒有找到。 這裏是我一起工作的代碼:如何從用戶輸入python
import time
import random
#Intro tells player how to use program
def displayIntro():
print("Hello there, welcome to your Python Checklist.")
time.sleep(2)
print("Please type the name of the chore e.g. rubbish.")
time.sleep(2)
print("To remove a completed chore, type ‘done’ then the name of the chore e.g. done rubbish.")
time.sleep(3)
print("It will tick the box next to the chore you said. ☑")
time.sleep(2)
print("To show unfinished chores type ‘display’ with check boxes next to them. ☐")
#Stores user input in a list
def nameChores():
chores = ''
chores2 =()
chores3 = ''
chores2 = input('Type chore name: ').split()
print("Chore(s) is now stored.")
while chores != 'display' and chores in chores2:
time.sleep(0.5)
print('Make sure to look at the intro for the commands.')
chores = input().lower()
#Displays the unfinished chores that the player has typed in and appear with unfilled checkboxes next to them
if chores == 'display':
print(chores2)
return chores
#Program looks for chore name and removes it from the list. Says to player it is removed with a tick next to it.
if chores in chores2:
chores2.remove(chores)
print("Chore is now remove. ☑")
nameChores()
這是你想要的嗎? http://stackoverflow.com/questions/2793324/is-there-a-simple-way-to-delete-a-list-element-by-value-in-python –