我正在寻找某种方式来询问用户输入字符串,一旦完成,我想在控制台中打印所有响应。像下面一样。
while True:
cityName = input("Write the name of the city visited and hit enter,
if you have another city write it after, once you are done, enter
no. ")
#Forexample user wrote, NY [hit enter], Los Angeles [hit enter],
#London [hit enter] No.
if cityName == 'no':
break
counter += 1 //Not sure about this part.
print(cityName.counter + ",") #Not sure about this part
#I want it to print NY, Los Angeles, London.
构建城市名称列表。然后打印列表项目的串联值。
city_names = []
while True:
city_name = input(
'Write the name of the city visited and hit enter, '
'if you have another city write it after, once you '
'are done, enter no. ')
if city_name == 'no':
break
city_names.append(city_name)
print(', '.join(city_names))