Python Repeat and Return

Asked 2 years ago, Updated 2 years ago, 110 views

#lay.py
import time

def loop():
    x=1
    y = 0
    while x==1:
        time.sleep(1)
        y = y +1
        return str(y)

I wrote this code roughly.

import lay
self.text_browser.setPlainText(lay.loop())

The problem is that if you write it like this, the return terminates the repetition, so it just ends with 1.

self.~ Is there a way to get the return value that keeps being updated without a repeat statement?

I think the question is very difficult. It's cold in the early morning, so be careful not to catch a cold!

python pyqt5

2022-09-20 19:08

1 Answers

The function ends when the return is performed return.

I think you can use it as follows.

import time

def loop(y):
    y = int(y) + 1
    return str(y)

x=1
while x==1:
    y = input ('input:')
    print(loop(y))
    time.sleep(1)


2022-09-20 19:08

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.