所以我刚刚开始学习python,从一些冗长的youtube教程开始。一个教程希望我创建一个启动和停止汽车的sim/游戏。我的代码与解决方案非常相似。我不确定有什么问题。具体的问题是,当汽车已经启动或停止时,程序无法返回打印功能——它只是重申启动/停止打印,就好像指示汽车是否开启或关闭的布尔代码目前不存在一样。
start = input('Enter "help" to see instructions: ').lower()
if start == 'help':
started = False
user_input = input("start - start the car\nstop - stop the car\nquit - exist program\n").lower()
while True:
if user_input == "start":
if started:
print("The car is already on.\n") #so if i enter start two times in a row, the second time it should print "The car is already on."
else:
started = True
print("The car has started. Now what?\n")
elif user_input == "stop":
if not started:
print("The car is already stopped.\n")
else:
started = False
print("The car has stopped. Now what?\n") #if this is the first command entered after "help", it should be printing "The car is already stopped." but doesn't do that.
elif user_input == 'quit':
break
else:
print("This is not a valid command.")
您需要继续user_input在time循环中。只需将user_input移动到time循环中。
start = input('Enter "help" to see instructions: ').lower()
if start == 'help':
started = False
while True:
user_input = input("start - start the car\nstop - stop the car\nquit - exist program\n").lower()
if user_input == "start":
if started:
print("The car is already on.\n") #so if i enter start two times in a row, the second time it should print "The car is already on."
else:
started = True
print("The car has started. Now what?\n")
elif user_input == "stop":
if not started:
print("The car is already stopped.\n")
else:
started = False
print("The car has stopped. Now what?\n") #if this is the first command entered after "help", it should be printing "The car is already stopped." but doesn't do that.
elif user_input == 'quit':
break
else:
print("This is not a valid command.")
这里是输出:
[evaluate untitlewerwd-1.py]
Enter "help" to see instructions: help
start - start the car
stop - stop the car
quit - exist program
start
The car has started. Now what?
start - start the car
stop - stop the car
quit - exist program
start
The car is already on.
start - start the car
stop - stop the car
quit - exist program
stop
The car has stopped. Now what?
start - start the car
stop - stop the car
quit - exist program
stop
The car is already stopped.
start - start the car
stop - stop the car
quit - exist program
stop
The car is already stopped.
start - start the car
stop - stop the car
quit - exist program
quit
参考 workerman手册 http://doc3.workerman.net/install/start-and-stop.html
注意Workerman启动停止等命令都是在命令行中完成的。 要启动Workerman,首先需要有一个启动入口文件,里面定义了服务监听的端口及协议。可以参考入门指引--简单开发实例部分 这里以workerman-chat为例,它的启动入口为start.php。 启动 以debug(调试)方式启动 php start.php start 以daemon(守护进程)方式启动 php start.php
本文向大家介绍Linux启动/停止/重启Mysql数据库的简单方法(推荐),包括了Linux启动/停止/重启Mysql数据库的简单方法(推荐)的使用技巧和注意事项,需要的朋友参考一下 1、查看mysql版本 方法一:status; 方法二:select version(); 2、Mysql启动、停止、重启常用命令 a、启动方式 1、使用 service 启动: [root@localhost /]
本文向大家介绍C#实现简单的汽车租赁系统,包括了C#实现简单的汽车租赁系统的使用技巧和注意事项,需要的朋友参考一下 最近学习了继承,多态,集合,设计模式,有一个汽车租凭系统,给大家分享一下: 我们首先来看看我们这个系统的效果 1.做一个项目,我们首先对项目进行分析 根据我们最近学的知识,我们可以看出继承,多态,集合,设计模式,我们都能用到 我们把所需要的类和简单模式中的“简单工厂”的工厂准备好
Triathlon程序执行一个长时间运行的任务,如果该任务已完全执行,则有可能重新启动该任务。我想添加停止执行以重置UI的可能性。为了达到这个目的,我增加了一个新的按钮,停止。代码如下: 如果任务已经完成,程序很好地重新启动,但是如果我在停止它之后调用start,程序就会崩溃。我该纠正什么?
问题内容: 我正在尝试在内存模式下使用hsqldb创建集成测试。目前,我必须在运行单元测试之前从命令行启动hsqldb服务器。我希望能够通过集成测试来控制hsqldb服务器。我似乎无法通过代码解决所有问题。 更新: 这似乎与在类路径中包含hibernate.cfg.xml文件一起使用: 并在我的hibernate.cfg.xml文件中: 更新 看来,这仅是在使用jUnit和内置测试运行器从Ecli