이 프로그램의 목적은 파티에 참석하는 사람들의 이름 목록을 만드는 것입니다. 루프를 종료하는 옵션으로 YES를 선택할 때까지 이름 추가를 계속할 수있는 권한을 사용자에게 부여 할 수 있기를 원합니다. 그러나 우연히 누군가를 추가하거나 목록을 편집하고 다른 사람을 제거 또는 교체하려는 경우 제거하려는 이름을 입력하게되면 나는 밟았습니다.왜 나는 AttributeError가 발생합니까? 'str'객체에는 변수 또는 문자열을 사용하여 요소를 제거하려고 할 때 'remove'속성이 없습니다?
저는 프로그래밍에있어 초보자입니다. 따라서이 코드에 대한 수업이 부족합니다. 어떤 도움이라도 대단히 감사하겠습니다. 미리 감사드립니다.
#Initialize empty list
partyList = []
#Initilize empty entry
inviteeName = ''
endEntry = ''
#Run loop until YES is entered as a value
while endEntry != "Yes":
inviteeName = input("Please enter the name of the person you are inviting below." + "\nName: ")
inviteeName = inviteeName.title()
# Verifies if a name was not entered.
while inviteeName == "":
inviteeName = input("\nPlease enter the name of the person you are inviting below." + "\nName: ")
inviteeName = inviteeName.title()
endEntry = input("\tPress ENTER to continue or type Yes to finish: ")
endEntry = endEntry.title()
#Append every new name to the list
partyList.append(inviteeName)
#Adds the word "and" to finish sentence if there are more than one invitees. NOTE: Make a class please!
numOfInvitees = len(partyList)
if numOfInvitees > 1:
partyList.insert(-1, 'and')
#Remove brackets and quotes.
partyList = ', '.join(partyList)
#Print message
print("\nThis will be your final message:\n" + str(partyList) + "\nYou are invited to my party!\n")
나는 우연히 입력 한 이름을 제거하는 데 도움이되도록이 도구를 사용하려고했습니다. 여기
submit = input('Submit?: '.title())
submit = submit.title()
if submit == 'Yes':
print('Invite has been sent!')
elif submit == 'No':
remNameConfirmation = input('Would you like to remove a name from the list?: ')
remNameConfirmation = remNameConfirmation.title()
if remNameConfirmation == 'Yes':
uninviteName = (input('Who would you like to remove?: '))
uninviteName = uninviteName.title()
은 당신의 코드를 문자열로 변수
partyList
을 설정합니다
partyList = ', '.join(partyList)
에 도달 할 때 몇 가지 문제
partyList.remove(uninviteName)
print(partyList)
'partyList =', '.join (partyList)'이것은 목록을 문자열로 변환합니다. 'partyListAsString = ','.join (partyList)'와 같은 것을 사용하면 두 표현을 분리하여 유지할 수 있습니다. –
켄 감사합니다. 너와 제임스 둘 다 내가 잘못한 것을 분명히했다. 하하. – codeHunter