我是新来的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