我是新來的Python,我正在嘗試創建一個非常簡化的foursquare版本。Python詞典
我希望用戶能夠登記入住以及通過日期和地點搜索他們之前的登記入住。我所擁有的代碼似乎可以在簽入時正常工作,但搜索不會將結果返回給用戶。我知道我在for
循環中的字詞已關閉,但我對如何搜索字典感到困惑。
非常感謝您的幫助。
print("What would you like to do? \n1 Check-in \n" \
"2 Search check-ins by date \n3 Search check-ins by location \n4 Exit")
while True:
import datetime
current_date = str(datetime.datetime.now())
check_in = {}
choice = input("\nYour choice: ")
if choice == '1':
location = input("\nPlease enter your current location: ")
check_in[current_date] = location
print("You have checked in at", location, current_date)
elif choice == '2':
date_search = input("Please enter a date (yyyy/mm/dd) ")
for date in check_in.keys():
if date_search in check_in(date):
print(check_in[key])
elif choice == '3':
location_search = input("Please enter a location: ")
for date in check_in.keys():
if location_search in check_in(date):
print(date)
elif choice == '4':
break
這是Python 2.x還是Python 3.x? 'input()'在兩個版本之間做了不同的事情。 – Makoto 2012-04-17 01:28:51
'如果check_in中的location_search(日期):''如果location_search == check_in(日期):' – Alan 2012-04-17 01:29:59
謝謝你的全部幫助。這是python3,對不起,以前沒有指定。 – user1337582 2012-04-17 02:20:22