我是 Python 新手,正在尝试创建一个非常简化的foursquare 版本。
我希望用户能够签到以及按日期和位置搜索他们以前的签到。我拥有的代码似乎可以在签入时正常工作,但搜索并未将结果返回给用户。我知道我在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