小编Bil*_*ljk的帖子

Python字典

我现在在python中做字典,我试图访问profile.keysprofile.items命令.所有这一切都会<dict_values object at 0x107fa50>出现.我该怎么办?

python

3
推荐指数
2
解决办法
8155
查看次数

在Python中乘以二进制数

假设我有二进制数0b110,这是6,我想将数字乘以3,得到18即0b10010.我将如何在Python中执行此操作,我尝试将其正常乘以,但它不起作用...

python binary

3
推荐指数
1
解决办法
4239
查看次数

Ruby if语法(两个表达式)

假设您使用的ifRuby语法如下:

if foo == 3: puts "foo"
elsif foo == 5: puts "foobar"
else puts "bar"
end
Run Code Online (Sandbox Code Playgroud)

有没有办法做到这一点,所以Ruby在if语句中执行两件事,比如说:

if foo == 3
    puts "foo"
    foo = 1
elsif foo = ...
Run Code Online (Sandbox Code Playgroud)

我怎么能这样做,所以我可以使用第一个语法放两个语句?

ruby syntax if-statement

3
推荐指数
2
解决办法
586
查看次数

tcl和Python之间的相似之处

现在,我正在学习Python和Javascript,有人最近向我建议我学习tcl.作为编程的相对菜鸟,我不知道tcl是什么,如果它类似于Python.因为我喜欢python,我想知道两者有多相似,所以我可以看看我是否想要启动它.

python tcl

2
推荐指数
1
解决办法
3325
查看次数

Python中的整数错误

所以我做了一个非常简单的程序,从99开始倒数(唱99瓶啤酒),但我一直得到2个错误中的1个

#!/usr/bin/env python
print("This program sings the song 99 bottles of beer on the wall")
lim = input("What number do you want it to count down from?")
def sing():
    global lim
    while int(lim) >= 0:
        if int(lim) != 1 or int(lim) != 0:
            print(lim, "bottles of beer on the wall", lim, "bottles of beer")
            print("Take one down pass it around...")
            print(lim, "bottles of beer on the wall")
            input("\nPRESS ENTER\n")
            lim -= 1
sing()
TypeError: unsupported operand type(s) for -=: 'str' …
Run Code Online (Sandbox Code Playgroud)

python math integer numbers

2
推荐指数
1
解决办法
193
查看次数

Ruby Modulo Division

所以我创建了一个程序,使用模块在Ruby中进行模数除法:

module Moddiv
    def Moddiv.testfor(op1, op2)
        return op1 % op2
    end
end
Run Code Online (Sandbox Code Playgroud)

程序:

require 'mdivmod'
print("Enter the first number: ")
gets
chomp
firstnum = $_
print("Enter the second number: ")
gets
chomp
puts
secondnum = $_
puts "The remainder of 70/6 is " + Moddiv.testfor(firstnum,secondnum).to_s
Run Code Online (Sandbox Code Playgroud)

当我使用两个数字运行它时,比如70和6,我得到70作为输出!为什么会这样?

ruby modulo

2
推荐指数
1
解决办法
2万
查看次数

Rails Something is Wrong ......(noob)

我是一个菜鸟,我正在学习Steve Holzner撰写的"Begin on Ruby on Rails"一书.他告诉我要创建一个名为hello_controller的控制器,然后编辑控制器

class HelloController < ApplicationController
    def there
    end 
end
Run Code Online (Sandbox Code Playgroud)

然后他告诉我创建一个名为there.rhtml的文档,其中包含一些简单的HTML,并将其放在views/hello目录中.然后,我启动rails服务器,导航到localhost:3000/hello /那里,HTML的结果应该出现在页面上,我看到:

Routing Error

No route matches [GET] "/hello/there"

Try running rake routes for more information on available routes. 
Run Code Online (Sandbox Code Playgroud)

ruby controller ruby-on-rails

2
推荐指数
1
解决办法
161
查看次数

命令行界面Ruby

说我有代码:

print(">>> ")
command = gets
Run Code Online (Sandbox Code Playgroud)

我想要做的是command,通过在你想要执行的代码周围添加反引号,就像在Ruby中通常那样执行变量.我该怎么做?如果我做:

`command`
Run Code Online (Sandbox Code Playgroud)

它只是尝试执行word命令.我如何执行变量???

ruby

2
推荐指数
1
解决办法
190
查看次数

为什么Python使用模块?

为什么python使用模块,而不是仅仅包含主语言中的模块函数.这将是非常有用和非常简单的,特别是对于诸如random,re和os之类的主要内容.如果Python宣扬简单和极简主义,为什么还要编写额外的代码行?

python module

1
推荐指数
1
解决办法
284
查看次数

Ruby意外的kEND,期待$ end

require 'open-uri'
print "Enter a URL"
add = gets
open(#{add}) do |f|
  j = f.read.scan(/<img/)
  jlen = j.length
  puts jlen
end
Run Code Online (Sandbox Code Playgroud)

是我的代码.出于某种原因,红宝石给了我一个错误:findimages.rb:8: syntax error, unexpected kEND, expecting $end 这是为什么?

ruby

1
推荐指数
1
解决办法
6144
查看次数