为什么我对以下代码出错?
def test(s)
tester = s.split(//)
for char in tester
if char != 1 or char != 0
return false
end
end
return true
end
puts test("11111000")
# => false
Run Code Online (Sandbox Code Playgroud)
提前谢谢你的回答!
我试着写一个函数,它能够随机改变单词中的字母,除了第一个和最后一个.
def fun(string)
z=0
s=string.size
tab=string
a=(1...s-1).to_a.sample s-1
for i in 1...(s-1)
puts tab[i].replace(string[a[z]])
z=z+1
end
puts tab
end
fun("sample")
Run Code Online (Sandbox Code Playgroud)
我的输出是:
p
l
a
m
sample
Run Code Online (Sandbox Code Playgroud)
有人知道如何使我的标签正确吗?它似乎改变了阻止,因为在输出中是"plamp"所以它是随机的,因为我想要但如果我想打印整个单词(splampe)它不起作用.:(
我想做以下工作.
if not a; then puts a + " is not defined"
if not b; then puts b + " is not defined"
...
if not f; then puts f + " is not defined"
Run Code Online (Sandbox Code Playgroud)
为了做到这一点,我必须输入许多单词.有没有更简单的方法来解决它?例如,
for i in %w[a b c d e f] do
if not i; then puts i + " is not defined"
end
Run Code Online (Sandbox Code Playgroud)
我知道上面的代码不起作用,但我仍然想知道是否有这么简单的方法来做到这一点.
下面的代码真的很烦我,我已经看了stackoverflow和谷歌但还没有找到任何东西,我是一个非常好的python程序员,还没有,直到现在,发现一个我无法处理的错误.
我已经尝试了一切,但这段代码给了我
IndentationError: unexpected unindent
Run Code Online (Sandbox Code Playgroud)
这是奇怪的,因为正常的错误是"不期望的缩进",这意味着多次张贴其间距和我如何间隔它所以我经历了整个代码和nada相同的错误,我正确地放入四个空格,一切仍然.. . 没有.救命?
该脚本是出于安全原因和webapp.
#!/usr/bin/python
#!/usr/bin/python
#Greets:SEC4EVER Members.
import hashlib
import base64
import socket
print"""
___ ___ _ _____ _____
| \/ || | |_ _|_ _|
| . . || | | | | |
| |\/| || | | | | |
| | | || |____| | _| |_
\_| |_/\_____/\_/ \___/
v0.1
"""
def main():
print '1 - SHA1 Decrypter'; print
print '2 - MD5 Decrypter'
print '3 - Base64 Decrypter' …Run Code Online (Sandbox Code Playgroud)