如何解决它正在继续打印
当我运行这段代码时,它不断给我答案 这是我的代码
$ ejabberdctl get_room_options room1 conference.localhost
title
public true
moderated true
...
$ ejabberdctl change_room_option room1 conference.localhost title ABCD
$ ejabberdctl change_room_option room1 conference.localhost moderated false
$ ejabberdctl change_room_option room1 conference.localhost public false
$ ejabberdctl get_room_options room1 conference.localhost
title ABCD
public false
moderated false
...
解决方法
您可能想要的是将输入获取代码放入 while 循环中:
while True:
num1 = float(raw_input("enter a number: ")) # type: float
operation = str(raw_input("enter a operation: "))
num2 = float(raw_input("enter a number: ")) # type: float
if operation == "+":
print (num1 + num2)
elif operation == "-":
print (num1 - num2)
elif operation == "*":
print (num1 * num2)
elif operation == "/":
print (num1 / num2)
else:
print("Error Error")
,
`while True:` means Infinite Loop.
您可以在 while 循环中获取输入,也可以更改 while 循环的条件。
,删除while True:
,它只会打印出一次答案。只要参数为真且 while
始终为真,True
循环就会继续运行 :P
您可能希望应用程序不断计算来自用户的输入。
试试这个
def calculate():
num1 = float(raw_input("enter a number: ")) # type: float
operation = str(raw_input("enter a operation: "))
num2 = float(raw_input("enter a number: ")) # type: float
if operation == "+":
print (num1 + num2)
elif operation == "-":
print (num1 - num2)
elif operation == "*":
print (num1 * num2)
elif operation == "/":
print (num1 / num2)
else:
print("Error Error")
while True:
calculate()
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。