当前时区为 UTC + 8 小时



发表新帖 回复这个主题  [ 9 篇帖子 ] 
作者 内容
1 楼 
 文章标题 : 大家帮帮忙,这个python的题目怎么写,后半个不知道什么意思?
帖子发表于 : 2012-04-07 21:08 

注册: 2007-01-10 9:32
帖子: 1038
送出感谢: 4
接收感谢: 5
Write a function slope(x1, y1, x2, y2) that returns the slope of the line through the points (x1, y1) and (x2, y2). Be sure your implementation of slope can pass the following doctests:

def slope(x1, y1, x2, y2):
"""
>>> slope(5, 3, 4, 2)
1.0
>>> slope(1, 2, 3, 2)
0.0
>>> slope(1, 2, 3, 3)
0.5
>>> slope(2, 4, 1, 2)
2.0
"""

Then a call to slope in a new function named intercept(x1, y1, x2, y2) that returns the y-intercept of the line through the points (x1, y1) and (x2, y2).

def intercept(x1, y1, x2, y2):
"""
>>> intercept(1, 6, 3, 12)
3.0
>>> intercept(6, 1, 1, 6)
7.0
>>> intercept(4, 6, 12, 8)
5.0
"""

intercept should pass the doctests above.


第一个还有一个没有测试通过。不知道错哪里,请帮忙看看。


附件:
slope1.png
slope1.png [ 171.24 KiB | 被浏览 1598 次 ]

slope.png
slope.png [ 237.75 KiB | 被浏览 1605 次 ]



_________________
ubuntu技巧 http://wiki.ubuntu.org.cn/index.php?tit ... 6.E5.8C.BA
页首
 用户资料  
 
2 楼 
 文章标题 : Re: 大家帮帮忙,这个python的题目怎么写,后半个不知道什么意思?
帖子发表于 : 2012-04-07 21:14 
头像

注册: 2010-06-16 1:05
帖子: 14668
地址: Tencent
系统: Mac OS X
送出感谢: 1
接收感谢: 153
鸟文看都看不求懂


_________________
twitter求fo:http://twitter.com/maplebeats
博客求踩:http://maplebeats.com


页首
 用户资料  
 
3 楼 
 文章标题 : Re: 大家帮帮忙,这个python的题目怎么写,后半个不知道什么意思?
帖子发表于 : 2012-04-07 21:24 

注册: 2007-01-10 9:32
帖子: 1038
送出感谢: 4
接收感谢: 5
求点(x1,y1) 和点(x2,y2)的斜率。
在测试里,有一个点始终通不过,不知道为什么?程序好像没问题啊。


_________________
ubuntu技巧 http://wiki.ubuntu.org.cn/index.php?tit ... 6.E5.8C.BA


页首
 用户资料  
 
4 楼 
 文章标题 : Re: 大家帮帮忙,这个python的题目怎么写,后半个不知道什么意思?
帖子发表于 : 2012-04-07 21:33 
头像

注册: 2009-04-11 23:46
帖子: 4130
系统: Arch Linux
送出感谢: 11
接收感谢: 124
请把代码贴出来,要在 Code 标签里。


_________________
我的博客 https://blog.lilydjwg.me/
提问的智慧
Arch Linux 中文论坛

我的vimrc: https://git.io/vimrc


页首
 用户资料  
 
5 楼 
 文章标题 : Re: 大家帮帮忙,这个python的题目怎么写,后半个不知道什么意思?
帖子发表于 : 2012-04-07 21:45 

注册: 2007-01-10 9:32
帖子: 1038
送出感谢: 4
接收感谢: 5
代码:
def slope(x1,y1,x2,y2):
    """
    >>> slope(5,3,4,2)
    1.0
    >>> slope(1,2,3,2)
    0.0
    >>> slope(1,2,3,3)
    0.5
    >>> slope(2,4,1,2)
    2.0
   
    """
   
   if x1 == x2:
        print "The slope doesn't exist"
        return
    else:
        return (float(y2-y1)) / (x2-x1)
if __name__ == '__main__':
    import doctest
    doctest.testmod()



_________________
ubuntu技巧 http://wiki.ubuntu.org.cn/index.php?tit ... 6.E5.8C.BA


页首
 用户资料  
 
6 楼 
 文章标题 : Re: 大家帮帮忙,这个python的题目怎么写,后半个不知道什么意思?
帖子发表于 : 2012-04-07 21:47 

注册: 2007-01-10 9:32
帖子: 1038
送出感谢: 4
接收感谢: 5
刚刚从新输了一便,又通过了,程序没问题。关键是第二题什么意思。


_________________
ubuntu技巧 http://wiki.ubuntu.org.cn/index.php?tit ... 6.E5.8C.BA


页首
 用户资料  
 
7 楼 
 文章标题 : Re: 大家帮帮忙,这个python的题目怎么写,后半个不知道什么意思?
帖子发表于 : 2012-04-07 22:13 
头像

注册: 2007-10-05 15:49
帖子: 404
送出感谢: 0 次
接收感谢: 0 次
就是求 穿过(x1, y1, x2, y2) 这条直线 与y轴的交点。。。。
代码:
def intercept(x1, y1, x2, y2):
       if x1==x2:

            print "The slope doesn't exist"
            return
    else:
        return y1 - (float(y2-y1)) / (x2-x1)*x1



当然根据题目的意思 你这个地方 (float(y2-y1)) / (x2-x1)要 调用 第一个题目所写的函数。。。。。


_________________
msoffice,autocad,我恨你们。。。。。。
我的blog


页首
 用户资料  
 
8 楼 
 文章标题 : Re: 大家帮帮忙,这个python的题目怎么写,后半个不知道什么意思?
帖子发表于 : 2012-04-07 22:19 

注册: 2007-01-10 9:32
帖子: 1038
送出感谢: 4
接收感谢: 5
vicwjb 写道:
就是求 穿过(x1, y1, x2, y2) 这条直线 与y轴的交点。。。。
代码:
def intercept(x1, y1, x2, y2):
       if x1==x2:

            print "The slope doesn't exist"
            return
    else:
        return y1 - (float(y2-y1)) / (x2-x1)*x1



当然根据题目的意思 你这个地方 (float(y2-y1)) / (x2-x1)要 调用 第一个题目所写的函数。。。。。


第而个题目是什么意思,没看懂啊。谢谢。程序不难,就是看不懂。
Then a call to slope in a new function named intercept(x1, y1, x2, y2) that returns the y-intercept of the line through the points (x1, y1) and (x2, y2). 这话的意思是?


_________________
ubuntu技巧 http://wiki.ubuntu.org.cn/index.php?tit ... 6.E5.8C.BA


页首
 用户资料  
 
9 楼 
 文章标题 : Re: 大家帮帮忙,这个python的题目怎么写,后半个不知道什么意思?
帖子发表于 : 2012-04-08 14:13 

注册: 2007-01-10 9:32
帖子: 1038
送出感谢: 4
接收感谢: 5
知道了,谢谢楼上。前面没仔细看楼主的回帖。测试成功了。


_________________
ubuntu技巧 http://wiki.ubuntu.org.cn/index.php?tit ... 6.E5.8C.BA


页首
 用户资料  
 
显示帖子 :  排序  
发表新帖 回复这个主题  [ 9 篇帖子 ] 

当前时区为 UTC + 8 小时


在线用户

正在浏览此版面的用户:没有注册用户 和 1 位游客


不能 在这个版面发表主题
不能 在这个版面回复主题
不能 在这个版面编辑帖子
不能 在这个版面删除帖子
不能 在这个版面提交附件

前往 :  
本站点为公益性站点,用于推广开源自由软件,由 DiaHosting VPSBudgetVM VPS 提供服务。
我们认为:软件应可免费取得,软件工具在各种语言环境下皆可使用,且不会有任何功能上的差异;
人们应有定制和修改软件的自由,且方式不受限制,只要他们自认为合适。

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
简体中文语系由 王笑宇 翻译