pyschools的Private Test Cases通不过

软件和网站开发以及相关技术探讨
回复
头像
renxinzhi
帖子: 970
注册时间: 2007-11-02 13:46

pyschools的Private Test Cases通不过

#1

帖子 renxinzhi » 2012-11-07 15:40

# This is a comment
127.0.0.1 localhost
192.168.2.253 pyschools # python server

Examples

>>> gethostname('127.0.0.1')
'localhost'
>>> gethostname('192.168.2.253')
'pyschools'
>>> gethostname('192.168.2.254') # Returns 'Unknown host' if ip address is not found.
'Unknown host'

代码: 全选

# Write a function that reads the /etc/hosts and return the hostname, given the ip address.
def gethostname(ip_address):
    for line in open("/etc/hosts"):
        line = line.rstrip()
        if ip_address in line:
            return line.split(' ')[-1]
            break
    else:
        return "Unknown host"
图片
官方给出的解释是
What does it mean when I failed the Private Test Cases?
Private test cases are hidden test cases created to prevent the users from hardcoding the answers to the visible test cases. If you fail the private test cases, look at the samples for some clues that you may miss. For example, there may be a missing '\n' or ' ' (space) which is not apparent between the Returned and Expected results.
费了老大劲,还是不知道哪里出错。
明察,慎思,笃行
回复