小编nei*_*eil的帖子

学习python艰苦的方式锻炼18帮助

我理解除第一个以外的所有功能.什么(*args)是什么意思?

谢谢

def print_twice(*args):
    arg1, arg2 = args
    print 'arg1: %r arg2: %r' % (arg1, arg2)

def print_twice_again(arg1, arg2):
    print 'arg1: %r arg2: %r' % (arg1, arg2)

def print_once(arg1):
    print 'arg1: %r' % arg1

def print_none():
    print 'i got nothin...'

print_twice("neil", "harper")
print_twice_again("neil", "harper")
print_once("first!")
print_none()
Run Code Online (Sandbox Code Playgroud)

python

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

帮助理解lisp中的这一行

(defun dump-db ()
  (dolist (cd *db*)
    (format t "~{~a:~10t~a~%~}~%" cd)))
Run Code Online (Sandbox Code Playgroud)

dolist使*db*变量对应的列表的每个元素cd

并且~a意味着以更易读的形式打印它,但这两个让我感到困惑.

~{ ~}这是否意味着中间的任何内容*db*将被格式化为每个元素的方式?

什么是:~{~a:

lisp common-lisp

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

学习python艰苦的运动35帮助

出于某种原因,当游戏到达黄金房间时,它无法正常工作.当我输入任何数字我得到死亡信息'男人,学会输入一个数字'

谢谢

from sys import exit

def gold_room():
    print 'this room is full of gold, how much do you take?'

    next = raw_input('> ')
    if '0' in next or '1' in next:
        how_much = int(next)
    else:
        dead('man, learn how to type a number')


    if how_much < 50:
        print 'nice! your not too greedy. you win!'
        exit(0)
    else:
        dead('you greedy bastard!')


def bear_room():
    print 'there is a bear here.'
    print 'the bear has a bunch of honey'
    print 'the fat bear …
Run Code Online (Sandbox Code Playgroud)

python

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

学习python艰难的方式锻炼40帮助

嘿家伙,我无法理解这一点,当地图被真正引用到城市字典时,我得不到.或者最后一行,(城市,州)部分是什么?

谢谢.

cities = { 'CA': 'San Francisco', 'MI': 'Detroit', 'FL': 'Jacksonville'}

cities['NY'] = 'New York'
cities['OR'] = 'Portland'

def find_city(themap, state):
    if state in themap:
        return themap[state]
    else:
        return 'not found'

#ok pay attention!
cities['_find'] = find_city

while True:
    print 'State? (ENTER to quit)'
    state = raw_input('> ')

    if not state: break

    #this line is the most important ever! study!
    city_found = cities['_find'] (cities, state)
    print city_found
Run Code Online (Sandbox Code Playgroud)

python

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

不确定这条线的作用

(or (parse-integer (prompt-read "Rating") :junk-allowed t) 0)
Run Code Online (Sandbox Code Playgroud)

这条线让我很困惑.如果你需要它,完整的程序就在这里:http://paste.lisp.org/display/124929

'Parse-integer'会将字符串转换成整数吗?如果可能的话.并且':junk-allowed t'让它以某种方式接受垃圾串吗?

不知道最后的'或'和0是什么.

谢谢.

lisp common-lisp

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

标签 统计

python ×3

common-lisp ×2

lisp ×2