私は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()'は2つのバージョン間で異なることを行います。 – Makoto
'check_in(date)のlocation_search:' to 'location_search == check_in(date):' – Alan
ありがとうございました。これはPython3です。以前は指定しておかないと残念です。 – user1337582