有没有办法找出问题所在?
Is there a way to figure out what's wrong?
我写了那些代码,它们 运行 很好,并给出了正确的答案,但突然他们开始给我错误的答案或直接进入下一个代码,我不知道发生了什么?
正确输入城市时,告诉我从可用选项中进行选择!和月份:月份写得正确,但仍然不是月份和日期???!
enter code here
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
cities = ['chicago', 'new york', 'washington']
city = input('Choose a city: \n >').lower()
if city not in cities:
city = input('Choose from available Cities: Chicago, New York or Washington: \n >').lower()
if city == 'new york':
city = 'new york city'
# get user input for month (all, january, february, ... , june)
months = ['all', 'January', 'Feburary', 'March', 'April', 'May', 'June']
month = input('Please select month or for all months type "all": \n >').lower()
if month not in months:
month = 'all'
print("This month is not available so it's gonna be all")
# get user input for day of week (all, monday, tuesday, ... sunday)
days = ['all', 'Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
day = input('Please Choose specific day or for all days type "all": \n >')
if day not in days:
day = 'all'
print("That day isn't available, so it's gonna be all")
month = input('Please select month or for all months type "all": \n >')
删除 lower() 否则将月列表中的元素更改为小写。
答案是将列表中的变量设为小写
现在有用了
但仍然不知道它在使用大写字母之前是如何工作的,就像我发布的那样。
我写了那些代码,它们 运行 很好,并给出了正确的答案,但突然他们开始给我错误的答案或直接进入下一个代码,我不知道发生了什么? 正确输入城市时,告诉我从可用选项中进行选择!和月份:月份写得正确,但仍然不是月份和日期???!
enter code here
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
cities = ['chicago', 'new york', 'washington']
city = input('Choose a city: \n >').lower()
if city not in cities:
city = input('Choose from available Cities: Chicago, New York or Washington: \n >').lower()
if city == 'new york':
city = 'new york city'
# get user input for month (all, january, february, ... , june)
months = ['all', 'January', 'Feburary', 'March', 'April', 'May', 'June']
month = input('Please select month or for all months type "all": \n >').lower()
if month not in months:
month = 'all'
print("This month is not available so it's gonna be all")
# get user input for day of week (all, monday, tuesday, ... sunday)
days = ['all', 'Saturday', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday']
day = input('Please Choose specific day or for all days type "all": \n >')
if day not in days:
day = 'all'
print("That day isn't available, so it's gonna be all")
month = input('Please select month or for all months type "all": \n >')
删除 lower() 否则将月列表中的元素更改为小写。
答案是将列表中的变量设为小写 现在有用了 但仍然不知道它在使用大写字母之前是如何工作的,就像我发布的那样。