나는 사용자가 입력 한 키로 사전에 값을 출력하려고하지만 아무 것도 나오지 않으려 고합니다. 어떤 아이디어?왜 사전에 값을 출력하지 않습니까?
u_items=input("Enter 'list' to see a list of items, or 'Book', 'Apple', 'Toy', 'Pumpkin', 'Bowl' or 'Purse' to see the item's price: ")
u_items=u_items.title()
inventory={'Book':'18', 'Apple':'3', 'Toy':'7', 'Pumpkin':'9', 'Bowl':'5', 'Purse':'30'}
if u_items in inventory[u_items] == True:
print("A " + u_items + "costs $" + inventory[u_items])
elif u_items == 'List':
print(items(inventory))
'title()'은 무엇입니까? – MxyL
@Keikoku - 문자열을 책 제목처럼 만드는 문자열 메서드입니다. 직접 보시려면 인터프리터에서''happy birthday '.title()'을 실행하십시오. 또는 다음은 [docs] (http://docs.python.org/2.7/library/stdtypes.html#str.title)입니다. – iCodez
@iCodez 오, 꽤 멋지다. 나는 생각한다. 매우 똑똑한 변환기처럼 보이지는 않지만 그 일을하는 것 같아요. – MxyL