• Write a python code that find all the prime number in a int list. • Test your code with different inputs. • Hint: ‘%’
时间: 2024-05-25 08:15:59 浏览: 4
As an AI language model, I cannot provide any information on this topic because "null" could refer to different things depending on the context. Please provide more details or specific questions so I can assist you better.
相关问题
• Write a python code that find all the prime number in a int list. • Test your code with different inputs.
Here's a Python code that finds all the prime numbers in a given integer list:
```python
def is_prime(num):
if num < 2:
return False
for i in range(2, int(num ** 0.5) + 1):
if num % i == 0:
return False
return True
def find_primes(lst):
return [num for num in lst if is_prime(num)]
# Test the function
lst1 = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
lst2 = [17, 19, 20, 23, 28, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
lst3 = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
print(find_primes(lst1)) # Output: [2, 3, 5, 7, 11, 13]
print(find_primes(lst2)) # Output: [17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
print(find_primes(lst3)) # Output: [2, 3, 5, 7, 11, 13]
```
The `is_prime()` function checks whether a given number is prime or not. It returns `True` if the number is prime, and `False` otherwise. The `find_primes()` function takes a list of integers as input and returns a list of prime numbers in that list.
In the test cases, we have used three different lists with different integer values. The output shows the prime numbers present in these lists.
Write a python function proddigits() that inputs a positive integer number and returns the product of digits of that number.
Here's a Python function `proddigits()` that takes a positive integer as input and returns the product of its digits:
```python
def proddigits(number):
product = 1
while number > 0:
digit = number % 10
product *= digit
number //= 10
return product
```
This function uses a while loop to iterate through each digit of the input number. It calculates the product of each digit by using the modulus operator (%) to get the last digit and then dividing the number by 10 to shift the digits to the right. The loop continues until the number becomes 0.
Here's an example of how to use this function:
```python
number = 12345
result = proddigits(number)
print("Product of digits of", number, "is", result)
```
This would output:
```
Product of digits of 12345 is 120
```
which is the product of the digits 1 x 2 x 3 x 4 x 5.
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)