【问题标题】:Loop won't continue after an if statementif 语句后循环不会继续
【发布时间】:2021-03-23 05:52:04
【问题描述】:

我是 python 循环的新手,如果 google 表格上特定单元格的值更改为 30 或以下,我会尝试结束循环。我尝试使用“继续”而不是“中断”,并且尝试缩进下一个循环以与 if 语句对齐,但似乎没有任何效果。第一个循环运行良好,但是当满足正确的条件时,它不会继续到下一个循环,只是重复第一个循环。到目前为止,这是我所拥有的:

        for b in range(179):

            time.sleep(5)

            #Get screenshot
            pyautogui.screenshot("Volume.png")

            #Crop out volume number
            im = Image.open("Volume.png")

            x1 = 2570
            y1 = 607
            x2 = 2671
            y2 = 637

            cropped = im.crop((x1, y1, x2, y2))

            cropped.save("Volume.png")

            #Convert image to text
            img = cv2.imread("Volume.png")

            text = image_to_string(img)

            #Import current volume 
            sheet.update_cell(3,2, text)



            change = sheet.cell(3,5).value
            floatt = float(change)

            if floatt <= 30:
                
                break

        #Start price
        for c in range(1):

            #Get screenshot
            pyautogui.screenshot("Price.png")

            #Crop out price number
            im = Image.open("Price.png")

            x1 = 1854
            y1 = 988
            x2 = 2074
            y2 = 1036

            cropped = im.crop((x1, y1, x2, y2))

            cropped.save("Price.png")

            #Convert image to text
            img = cv2.imread("Price.png")

            text = image_to_string(img)

            #Import start price
            sheet.update_cell(9,2, text)

【问题讨论】:

    标签: loops if-statement google-sheets break continue


    【解决方案1】:

    试试这个:

    if floatt <= 30:
        break
    else:
        continue
    

    【讨论】:

    • 感谢您的快速回复!!!当然,一旦我发布它,我自己就发现了这个问题,哈哈
    【解决方案2】:

    我想通了。我的代码是正确的,我在运行时不小心手动弄乱了结果!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-08-03
      • 2017-03-03
      • 1970-01-01
      • 2016-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-11-03
      相关资源
      最近更新 更多