我最近开始在Prolog中编程,并且我正在尝试创建在列表中的给定元素之后找到元素的规则.例如,我想find(2,X,[1,2,3,4]).结果3.
我到目前为止的尝试:
find(X,Y,[X,Y|Tail]):-
!.
find(X,Y,[_|Tail]):-
find(X,Y,Tail).
Run Code Online (Sandbox Code Playgroud) 我最近开始用Python编码,遇到一个问题,将函数返回的值赋给变量.
class Combolock:
def _init_(self,num1,num2,num3):
self.x = [num1,num2,num3]
def next(self, state):
print "Enter combination"
combo = raw_input(">")
if combo == self.x[state]:
print "Correct"
return 1
else:
print "Wrong"
return 0
def lock(self):
currentState = 0
while currentState < 2:
temp = next(currentState)
if temp == 1:
currentState = currentState + 1
else:
currentState = 99
print "ALARM"
Run Code Online (Sandbox Code Playgroud)
当我调用锁定函数时,我在行处出错
temp = next(currentState)
Run Code Online (Sandbox Code Playgroud)
说int对象不是迭代器.
在Excel中,我有一列名称为"FirstName LastName"的名称.我想将整个列分成两列,一列包含所有名字,另一列包含所有姓氏.
我的代码到目前为止:
'Splitting the Traveler Display Name column
Dim SplitPoint As Long
'L2 is the column containing names to be split
Range("L2").Select
Do Until IsEmpty(ActiveCell)
'Search for position of space within the cell
SplitPoint = InStrRev(ActiveCell, " ", -1, vbTextCompare)
'Put the last name in the column next to the source column
ActiveCell.Offset(0, 1) = Trim(Left(ActiveCell, SplitPoint))
'Replace the source column with the first name
ActiveCell.Offset(0, 0) = Trim(Mid(ActiveCell, SplitPoint))
Loop
Run Code Online (Sandbox Code Playgroud)
到目前为止我找到的解决方案要求手动选择单元格,这对我正在使用的数据量是不合理的.我找到了这个解决方案,但是我收到以下错误:无效的过程调用或参数.