我现在正在为学校做一个小作业。你知道吗
我需要打印当前火车所在的车站和列表中剩下的车站。你知道吗
我使用了一个嵌套的for
循环,但无法使内部for
循环正常工作。我需要用+=1
创建一个变量吗?你知道吗
我的代码:
train_station=['Amsterdam-Central','Amsterdam-Amstel','Utrecht']
for x in train_station:
print("Current station is: "+x)
print("Stations to go: ")
begin=0
for y in range(begin,3,1):
print(train_stations[y])
我的输出:
Current station is: Amsterdam-Central
Stations to go:
Amsterdam-Central
Amsterdam-Amstel
Utrecht
Current station is: Amsterdam-Amstel
Stations to go:
Amsterdam-Central
Amsterdam-Amstel
Utrecht
Current station is: Utrecht
Stations to go:
Amsterdam-Central
Amsterdam-Amstel
Utrecht
差不多完成了,只需在每次迭代中增加
begin
。你知道吗还有一种更具脓性的解决方案:
相关问题 更多 >
编程相关推荐