大学里面学PYTHON,不过不太懂,想请教会的人一些问题,谢谢

大学里面学PYTHON,不过不太懂,想请教会的人一些问题,谢谢

我作业里面有几道不懂,会的人可以把步骤告诉我吗???
1。average(integerList)
Returns the mean value of the integers stored in the list integerList.
   要得出这样的结果:
average(integerList)
>>> average([5,7,8])
6.666666666666667
>>> average([10])
10.0
>>> average([1,2,3])
2.0


2。 playGame()
Repeatedly issues intelligent guesses to the guessing game you built in tutorial. See below for
more detailed information.
In tutorial, you saw a game that two players play together - one player chooses the number and
the other player guesses it, and the computer tells the 2nd player if the guess was too high or too
low. Now, you will write a computer program that actually plays the game – it will make smart
guesses until it finds the right answer.

要得出这样的结果:
playGame()
>>> game()
I guess 50
Am I too high (1), too low(2), or right on? (3)
1
I guess 25
Am I too high (1), too low(2), or right on? (3)
1
I guess 12
Am I too high (1), too low(2), or right on? (3)
2
I guess 18
Am I too high (1), too low(2), or right on? (3)
1
I guess 15
Am I too high (1), too low(2), or right on? (3)
2
I guess 16
Am I too high (1), too low(2), or right on? (3)
2
I guess 17
Am I too high (1), too low(2), or right on? (3)
3
I got it!

请问怎么做的啊?跪求步骤。。。。。。。。。。。。。。。。。。。。

一.

[Copy to clipboard] [ - ]
CODE:
list=[1,......]
float(sum(list))/len(list)



[Copy to clipboard] [ - ]
CODE:
from random import random

# 100<= answer <=0
def get_reply(c,rs,minr,maxr):
    if c==-1: r= int(random()*100)
    if c== 1:
        maxr.append(rs[-1])
        r = (min(maxr) + max(minr))/2
    if c== 2:
        minr.append(rs[-1])
        r = (min(maxr) + max(minr))/2

    rs.append(r)
    return r

def compare(reply, answer):
    if reply >answer:return 1
    if reply <answer:return 2
    return 3

def game(answer):
    replys =[]
    maxr =[100]
    minr =[0]
   
    c=-1
    while c!=3:
        r = get_reply(c,replys,minr,maxr)
        print 'I guess %d'%r
        print 'Am I too high (1), too low(2), or right on? (3)'
        
        c = compare(r,answer)
        print c
   
    print 'I got it'
   
if __name__ == '__main__':
    game(50)

大学里面有Python课程,你们真幸福啊。另外,感觉楼主有点,让人代做作业之嫌^_^


QUOTE:
原帖由 yuntinghill 于 2006-11-24 21:36 发表
一.

[Copy to clipboard] [ - ]
CODE:
list=[1,......]
float(sum(list))/len(list)


[code]from random import random

# 100<= answer <=0
def get_reply(c,rs,minr,maxr):
    if c==-1: r= int(random()*100)
...

强人就系强人啊~!好感激啊~


QUOTE:
原帖由 janusle 于 2006-11-25 17:08 发表
大学里面有Python课程,你们真幸福啊。另外,感觉楼主有点,让人代做作业之嫌^_^

我一点都不觉得幸福啊,好难啊~10几道问题做了一个都星期都没有做完,哎。。。。
不好好学习的结果,哈哈哈
bu shi ba...
da xue dou you python a~
wo men lao shi hai mei ting guo python ne
哪个学校的啊,这么NB
我怎么感觉是清华的那本python1.5用python学编程的实例