小编use*_*975的帖子

无法使我的计数功能在Python中工作

我正在尝试创建一个函数,您可以在单词"banana"中添加诸如"ana"之类的短语,并计算它在单词中找到短语的次数.我找不到我正在制作的一些测试单元无法正常工作的错误.

def test(actual, expected):
    """ Compare the actual to the expected value,
        and print a suitable message.
    """
    import sys
    linenum = sys._getframe(1).f_lineno   # get the caller's line number.
    if (expected == actual):
        msg = "Test on line {0} passed.".format(linenum)
    else:
        msg = ("Test on line {0} failed. Expected '{1}', but got '{2}'.".format(linenum, expected, actual))
    print(msg)

def count(phrase, word):
    count1 = 0
    num_phrase = len(phrase)   
    num_letters = len(word)    

    for i in range(num_letters):
        for x in word[i:i+num_phrase]:
             if phrase in word: …
Run Code Online (Sandbox Code Playgroud)

python function python-3.x

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

始终获得"无"的打印值

好吧,所以这里是我的代码,我得到了我想要的结果,但我不断得到它下面的"无"值.如何消除"无"值?

n = input("What day of the week are you leaving?")
r = input("How many days will you be resting?") 

def days(n):
    if n == 0:
        print "Sunday"
    elif n == 1:
        print "Monday"
    elif n == 2:
        print "Tuesday"
    elif n == 3:
        print "Wednesday"
    elif n == 4:
        print "Thrusday"
    elif n == 5:
        print "Friday"
    elif n == 6:
        print "Saturday"
    elif n >= 7:
        print days(n%7)



print days(n+r)
Run Code Online (Sandbox Code Playgroud)

python

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

Python中的真/假直角函数

我似乎无法正常工作。当我输入3代表a,2代表b和3.61代表c。这样可行。但是,当我以其他顺序尝试这些值时(例如:a为3.61,b为3,c为2),它将返回false。我不知道是什么问题。提前致谢!

a = input("Enter a ")
b = input("Enter b ")
c = input("Enter c ")


def isright_angled():
    if abs((a**2+b**2)-(c**2)) < 0.1 or abs((c**2-a**2)-(b**2)) < 0.1 or abs((c**2-b**2)-(a**2)) < 0.1:                         
        return True
    else:
        return False

print isright_angled()
Run Code Online (Sandbox Code Playgroud)

python geometry function

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

标签 统计

python ×3

function ×2

geometry ×1

python-3.x ×1