简体   繁体   中英

Functions do not run together in Python

Hello I am creating a small program that will take the multiples from a number and then determine which numbers are prime numbers. One problem I am having is that I am getting the following error when I run the program

RuntimeWarning: coroutine 'prime_number' was never awaited prime_number(multiples)

Here is my code: I am not sure what I am doing wrong as the multiples list populates with all the potential prime numbers, but the prime_number function appears to be skipped over entirely.

max = 20
num = 20
multiples = []
prime_numbers = []
def all_multiples(max):
    """finds all whole number multiples of max variable integer 
    and appends to multiples list"""
    for x in range(2, num):
        if max%x == 0:
            print(str(x) + " is a multiple!")
            multiples.append(x)
all_multiples(max)

def prime_number(multiples):
    """filters out multiples list for prime numbers and appends to prime_numbers list"""
    for x in multiples:
        if x/2 == 0:
            print("not a prime number")
        else:
            prime_numbers.append(x)
            print(str(x) + "is a prime number")
prime_number(multiples)
print(multiples)
print(prime_numbers)

好吧,现在看来运行良好...我不知道Visual Studio Code中的问题是什么,但我没有做任何更改...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM