Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/spring-boot/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
需要Python递减方面的帮助吗_Python - Fatal编程技术网

需要Python递减方面的帮助吗

需要Python递减方面的帮助吗,python,Python,好的!我得到的代码不能正常工作,下面是代码: def abDucks (a,b): while (a>1): print(a, "Little Ducks swimming in the sea") print("And if ",b," Little Ducks should accidentally drown") print("There'll be ", (a-b), "Little

好的!我得到的代码不能正常工作,下面是代码:

def abDucks (a,b): 
while (a>1): 
print(a, "Little Ducks swimming in the sea") 
print("And if ",b," Little Ducks should accidentally drown") 
print("There'll be ", (a-b), "Little Ducks swimming in the sea\n") 
a=(a-b) 

if (a<=1): 
print(a, "Little Ducks swimming in the sea") 
print("And if ",b," Little Ducks should accidentally drown") 
print("There'll be no Little Ducks swimming in the sea\n") 

您可以像这样简洁地编写相同的代码

def abDucks (a,b): 
    while (a - b >= 1):
        print(a, "Little Ducks swimming in the sea")
        print("And if ",b," Little Ducks should accidentally drown")
        print("There'll be ", (a-b), "Little Ducks swimming in the sea\n")
        a -= b
    else:
        print(a, "Little Ducks swimming in the sea")
        print("And if ",b," Little Ducks should accidentally drown")
        print("There'll be no Little Ducks swimming in the sea\n")
通过此更改,输出变为


请用正确的缩进编辑文章。请记住,Python中的缩进非常重要。我回滚了编辑。林奇,让奥普自己做缩进。我们可以做出一个很好的猜测,但我更愿意看看实际的缩进是什么。谢谢,伙计,这真的帮了大忙,我从昨天开始就一直试图弄清楚这一点,但我不知道发生了什么。非常感谢你!
def abDucks (a,b): 
    while (a - b >= 1):
        print(a, "Little Ducks swimming in the sea")
        print("And if ",b," Little Ducks should accidentally drown")
        print("There'll be ", (a-b), "Little Ducks swimming in the sea\n")
        a -= b
    else:
        print(a, "Little Ducks swimming in the sea")
        print("And if ",b," Little Ducks should accidentally drown")
        print("There'll be no Little Ducks swimming in the sea\n")
8 Little Ducks swimming in the sea
And if  2  Little Ducks should accidentally drown
There'll be  6 Little Ducks swimming in the sea

6 Little Ducks swimming in the sea
And if  2  Little Ducks should accidentally drown
There'll be  4 Little Ducks swimming in the sea

4 Little Ducks swimming in the sea
And if  2  Little Ducks should accidentally drown
There'll be  2 Little Ducks swimming in the sea

2 Little Ducks swimming in the sea
And if  2  Little Ducks should accidentally drown
There'll be no Little Ducks swimming in the sea