我正在制作一个程序,它使用一个循环来永远运行,我在下面有一段代码,向您展示我如何实现循环.这只是一个例子,而不是实际的程序.这是同样的想法.
import time
def start():
print "hello"
time.sleep(0.2)
start()
start()
Run Code Online (Sandbox Code Playgroud)
我所有的程序员朋友都告诉我不要这样做,而是使用while循环.像这样:
import time
def start():
while True:
print "Hello"
time.sleep(0.2)
start()
Run Code Online (Sandbox Code Playgroud)
当两种方法完美地运行时,为什么我应该使用while循环呢?
我为程序编写了一些代码,它给出了我定义为函数的序列的值f(x),但是当我运行它时会出现错误弹出'int' object is not callable".有人知道如何解决问题吗?
def f(x):
if x%2==0:
return x/2
else:
return 3*x+1
limite=int(input("parar en: "))
x=int(input("a1: "))
print(x)
n=1
while n<=limite:
f=f(x)
print(f)
n=n+1
print("fin")
Run Code Online (Sandbox Code Playgroud) 我怎样才能像这样整数整数?我调查了这个round()功能,但它没有我想要的东西.
5 > 0
9 > 0
11 > 20
14 > 20
19 > 20
20 > 40
29 > 40
Run Code Online (Sandbox Code Playgroud) 我在构建时遇到此错误:
dist/package.conf.inplace:
inappropriate type
FAILED DURING THE BUILDING PHASE. The **exception** was: ExitFailure 1
Run Code Online (Sandbox Code Playgroud)
如何subRegex 在 Text.Regex 包中使用?
我已经写了:
import Text.Regex.Posix
Run Code Online (Sandbox Code Playgroud)
但我得到了这个错误:
_.hs:13:5: Not in scope: ‘subRegex’
_.hs:13:15:
Not in scope: ‘mkRegex’
Perhaps you meant ‘makeRegex’ (imported from Text.Regex.Posix)
Run Code Online (Sandbox Code Playgroud)
所以,我去了Text.Regex[页] [1],然后说:
使用POSIX正则表达式接口
Text.Regex.Posix.
那么为什么不是这些功能在范围内呢?
python ×3
function ×1
ghc ×1
haskell ×1
python-2.7 ×1
regex ×1
scope ×1
sequence ×1
while-loop ×1