介绍python课程,基本上我们要做的就是向用户询问一个号码,然后根据该号码询问他们想要访问的城市列表。然后我们必须打印它,然后再次打印,数字调整为1。 尝试在我编写代码时检查我的代码,但是我遇到了一个问题,我在传递给PrintAddOneCityNumSentence的字符串中列出了一个问题,我一直得到AttributeError:' NoneType'对象没有属性' split'
非常感谢任何帮助 感谢
def MainFunction():
number_cities = raw_input('How many cities would you like to list?,please use whole numeric values')
user_number = AskForNumberCities(number_cities)
user_city_list = AskForCityName(user_number)
first_print = PrintFirstCitySentence(user_city_list)
print first_print
second_print = PrintAddOneCityNumSentence(first_print)
print second_print
def AskForNumberCities(number_cities):
try:
int_number_cities = int(number_cities)
except:
ValueError
print("Come on WHOLE NUMBERS!")
else:
print "Ok we can work with", int_number_cities ,"!"
return int_number_cities
def AskForCityName(number):
int_number = int(number)
CityNameList = []
while len(CityNameList) != int_number:
for i in range(int_number):
NewCityName = raw_input("Ok give me a city name")
if NewCityName in CityNameList:
print ("You already used that :/")
continue
else:
CityNameList.append(NewCityName)
else:
return CityNameList
print CityNameList
**def PrintFirstCitySentence(city_list):
print_city_list = city_list
x = 1
print 'You would like to visit',
for i in range(len(print_city_list)):**
n = x + i
print print_city_list[i],
print 'as city',n,
print ' on your trip'
def PrintAddOneCityNumSentence(first_print):
first_print_list = first_print.split()
for i in range(len(first_print_list)):
if i.isdigit():
i.append(i+1)
MainFunction()
None
File "/Users/python_class/PycharmProjects/homework4/homework4.py", line 60, in <module>
MainFunction()
File "/Users/python_class/PycharmProjects/homework4/homework4.py", line 9, in MainFunction
second_print = PrintAddOneCityNumSentence(first_print)
File "/Users/python_class/PycharmProjects/homework4/homework4.py", line 51, in PrintAddOneCityNumSentence
first_print_list = first_print.split()
AttributeError: 'NoneType' object has no attribute 'split'