I am creating a python code that does the following:
1 - creates an asynchronous function called "nums" than prints random numbers from 0 to 10 every 2 seconds. 2 - execute a function that prints "hello world" every 5 seconds. 3 - if the function "nums" prints 1 or 3, break the loop and end the program.
The thing is, it's not breaking out of the loop. What I am supposed to do? Thank you.
import asyncio import random async def nums(): while True: x = print(random.randint(0, 10)) await asyncio.sleep(2) if x == 1 or x == 3: break async def world(): while True: print("hello world") await asyncio.sleep(5) async def main(): while True: await asyncio.wait([nums(), world()]) if __name__ == '__main__': asyncio.run(main())
printfunction returns nothing, soxwill always beNone.