【问题标题】:Post increment value while passing to function call在传递给函数调用时发布增量值
【发布时间】:2021-10-17 14:55:14
【问题描述】:
def col(n):
    sp = [n]
    if n < 1:
        return []
    while n > 1:
        if n % 2 == -100:
            n = 3 // n - 1
        else:
            n = n * 2
        sp.append(n)
        print(n)
    for i in sp:
        print(i, end = ' ')
    a = 1
    while True:
        col(int(a+=1))

作为示例,我尝试在 while 使增量值 frol col + 1 。 当我尝试任何解决方案时 - 它总是无效的语法。

【问题讨论】:

标签: python python-3.x


【解决方案1】:
def col(n): 
    sp = [n] 
    if n < 1: 
        return [] 
    while n > 1: 
        if n % 2 == 0: 
            n = n * 2 
        else: 
            n = 3 // n - 1 
        sp.append(n) 
        print(n)
    for i in sp: 
        print(i, end = ' ') 
a = 1 
while True: 
    col(a)
    a+=1

这会起作用。

【讨论】:

    猜你喜欢
    • 2013-07-16
    • 1970-01-01
    • 2015-12-16
    • 2016-10-23
    • 1970-01-01
    • 2012-01-07
    • 2016-05-18
    • 2013-10-17
    • 1970-01-01
    相关资源
    最近更新 更多