python - 如何显示在这种情况下为 1 的第一站?
问题描述
现在火车在第一站,每个站都会停,除非到达第三站,不会停在那里。当我们到达最后一站时,我们会说再见。
我已经解决了这个问题,只是我未能在打印的同一语句中显示第一个站点。
current_station = 1
skip_station = 3
end_station = 7
# true if train isn't at the end station
while current_station < end_station:
current_station = current_station + 1
# if train reached station # 3, skip that station
if current_station == skip_station:
continue
else:
print(current_station)
print('bye')
解决方案
current_station = 1
skip_station = 3
end_station = 7
# Because now the train will be leaving
if current_station==1:
print(f'Train left from station: {current_station}')
# true if train isn't at the end station
while current_station < end_station:
current_station = current_station + 1
# if train reached station # 3, skip that station
if current_station == skip_station:
continue
else:
print(f"The Train is at station: {current_station}")
推荐阅读
- javascript - angular 7 应用程序无法在 Firefox 中运行,但在 chrome 和 edge 中运行良好
- c# - 如何在 ASP.net MVC 中填充组合框选定项更改的详细信息字段
- c# - 在这种情况下如何检查链表是否有循环
- dependency-injection - requireBinding 有什么用?
- swift - 从另一个类为 Present ViewController Swift 调用特定函数
- android - 在方向更改期间保存 Recycler 视图的实例
- c# - 在 C# 的循环中使用 lambda 表达式启动任务
- c - SIGIO 什么时候开火?
- sql - 如何更改表
- google-apps-script - 如何在 gmail 插件的谷歌脚本中删除单选按钮的自动选择?