我如何将 if 语句放入函数中?
How would I put an if statement inside a function?
我对 Python 非常陌生,在此之前我只使用非常简单的 "programming" 带有标签和 goto 的语言。我正在尝试让这段代码在 Sikuli 中工作:
http://i.imgur.com/gbtdMZF.png
基本上我希望它循环执行 if
语句,直到找到任何图像,如果找到其中一个图像,它就会执行正确的函数并再次开始循环,直到它检测到新命令。
我一直在寻找教程和文档,但我真的迷路了。我想我的思绪太忙于试图从一种 goto/label 转变为一种有组织的编程语言。
如果有人能给我一个例子,我将不胜感激!
在 Python 缩进问题中,您的代码应如下所示:
def function():
if condition1:
reaction1()
elif condition2:
reaction2()
else:
deafult_reaction()
我推荐阅读the chapter about indentation in Dive Into Python as well as PEP 0008。
x = input( "please enter the variable")
print(" the Variable entered is " + x)
myfloat = int(x)
def compare (num):
if num%2 == 0:
print(" entered variable is even")
else:
print("entered variable is odd")
compare(myfloat)
我对 Python 非常陌生,在此之前我只使用非常简单的 "programming" 带有标签和 goto 的语言。我正在尝试让这段代码在 Sikuli 中工作:
http://i.imgur.com/gbtdMZF.png
基本上我希望它循环执行 if
语句,直到找到任何图像,如果找到其中一个图像,它就会执行正确的函数并再次开始循环,直到它检测到新命令。
我一直在寻找教程和文档,但我真的迷路了。我想我的思绪太忙于试图从一种 goto/label 转变为一种有组织的编程语言。
如果有人能给我一个例子,我将不胜感激!
在 Python 缩进问题中,您的代码应如下所示:
def function():
if condition1:
reaction1()
elif condition2:
reaction2()
else:
deafult_reaction()
我推荐阅读the chapter about indentation in Dive Into Python as well as PEP 0008。
x = input( "please enter the variable")
print(" the Variable entered is " + x)
myfloat = int(x)
def compare (num):
if num%2 == 0:
print(" entered variable is even")
else:
print("entered variable is odd")
compare(myfloat)