擅长:python、mysql、java
<p>假设您的意思是说除非最后一个字符是零,否则所有的零都应该被忽略,那么下面的代码应该能够执行该任务</p>
<pre><code>def main(first, second):
first = first.lower()
second = second.lower()
string = ""
for i in range(0, (len(first)-1)):
if(first[i] != "0"):
string = string + first[i]
string = string + first[-1]
if(string == second):
return True
else:
return False
answer = main("A02A18", "a2a18")
print(answer)
answer = main("A15A20", "a15a2")
print(answer)
</code></pre>
<p>此代码为第一个调用返回<code>True</code>,为第二个调用返回<code>False</code>。将来,请记住<code>string.lower()</code>和<code>string.upper()</code>函数。在这种情况下,它们非常有用</p>