Untitled
unknown
python
3 years ago
2.7 kB
5
Indexable
import time import pandas as pd import numpy as np CITY_DATA = { 'chicago': 'chicago.csv', 'new york city': 'new_york_city.csv', 'washington': 'washington.csv' } chosen_cities = ['Chicago', 'New York', 'Washington'] months = ['January', 'February', 'March', 'April', 'May', 'June', 'All'] days_of_the_week = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday','Sunday','All'] def get_filters(): """ Asks user to specify a city, month, and day to analyze. Returns: (str) city - name of the city to analyze (str) month - name of the month to filter by, or "all" to apply no month filter (str) day - name of the day of week to filter by, or "all" to apply no day filter """ print('Hello! Let\'s explore some US bikeshare data!') # get user input for city (chicago, new york city, washington). HINT: Use a while loop to handle invalid inputs while True: city = input('Which city do you want to explore? Chicago, New York or Washington?').title() if city in chosen_cities: print ("Great Choice! You have selected {} Let's continue!".format(city)) break # print(city) #debug print - delete after program is working # print(chosen_cities) #debug print - delete after program is working else: print('Wrong input, please write Chicago, New York or Washington!') # TO DO: get user input for month (all, january, february, ... , june) while True: month = input('Which month do you select? January, February, March, April, May, June or all?').title() if month in months: print ("Great Choice! You have selected {} Let's continue!".format(month)) break # print(months)- wich months do we have else: print('Wrong input, please write either January, February, March, April, May, June or all') # TO DO: get user input for day of week (all, monday, tuesday, ... sunday) while True: day = input('Which day of the week do you select? Monday, Tuesday, Wednesday, Thursday, Friday, Saturday ,Sunday or all?').title() if day in days_of_the_week: print ("Great Choice! You have selected {} Let's continue!".format(day)) break # print(months)- wich months do we have else: print('Wrong input, please write either Monday, Tuesday, Wednesday, Thursday, Friday, Saturday ,Sunday or all') return city, month, day;
Editor is loading...