Hướng dẫn how do you find the product of a number in python? - làm thế nào để bạn tìm thấy sản phẩm của một số trong python?

Nhận một số và nhân các chữ số của số.

Mẫu đầu vào 1:

Nhập số: 234

Đầu ra mẫu 1:

24

Thiết kế biểu đồ dòng chảy

Chương trình hoặc giải pháp

				
				
					

num = int[input["enter a number"]]

n = num

product = 1

while n != 0:

    rem = n % 10

    product = product * rem

    n = n // 10

print[product]

Đầu ra

Giải thích chương trình

Khởi tạo sản phẩm bằng 1

Tính phần còn lại của một số bằng cách thực hiện số % 10, & nbsp; Nhân phần còn lại với tổng số và chia số cho 10 và lặp lại các bước trên cho đến khi số trở thành 0.

In sản phẩm, bạn sẽ nhận được sản phẩm của các chữ số của số.

5
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
51
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
60
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
08
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
09__

Làm thế nào để bạn tìm thấy sản phẩm trong Python?

Chúng ta có thể sử dụng numpy.prod [] từ nhập khẩu numpy để có được sự nhân của tất cả các số trong danh sách. Nó trả về một số nguyên hoặc giá trị float tùy thuộc vào kết quả nhân.

Làm thế nào để bạn tìm thấy sản phẩm của N số trong Python?

Sản phẩm của các chữ số của số sử dụng Python.

Thiết kế biểu đồ dòng chảy ..

Chương trình hoặc giải pháp. num = int [input ["nhập một số"]] n = num. ....

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]

Giải thích chương trình. Khởi tạo sản phẩm bằng 1 ..

Enter any number : 123456
Product of all digits in 123456 : 720

5

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
51
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
60
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
08
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
09__

Examples:  

Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
Input : list1 = [3, 2, 4] 
Output : 24 

Làm thế nào để bạn tìm thấy sản phẩm trong Python?Traversal

Chúng ta có thể sử dụng numpy.prod [] từ nhập khẩu numpy để có được sự nhân của tất cả các số trong danh sách. Nó trả về một số nguyên hoặc giá trị float tùy thuộc vào kết quả nhân.

Làm thế nào để bạn tìm thấy sản phẩm của N số trong Python?

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
67
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
77

Phương pháp 6: Sử dụng Traversal by Index

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
3
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
7
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
71
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
9
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
90__191919192

Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
1
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
3
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
3
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
5
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
01

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
2
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
8
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
9

Input : list1 = [3, 2, 4] 
Output : 24 
0
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
8

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
67
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5

6
24 
8
6
24 
9

6
24 
8
6
24 
1

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
7
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
71
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
9
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
73
Using numpy.prod[]

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
0
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
81

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
3
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5

Python3

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
7
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
71
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
9
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
90__191919192

Input : list1 = [3, 2, 4] 
Output : 24 
0
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
8

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
67
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
7
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
71
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
9
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
73

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
67
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
77

6
24 
8 9

6
24 
8 1

Output:   
 

6
24 

Phương pháp 6: Sử dụng Traversal by IndexUsing lambda function: Using numpy.array

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
0
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
81“return” statement, it always contains an expression that is returned. We can also put a lambda definition anywhere a function is expected, and we don’t have to assign it to a variable at all. This is the simplicity of lambda functions. The reduce[] function in Python takes in a function and a list as an argument. The function is called with a lambda function and a list and a new reduced result is returned. This performs a repetitive operation over the pairs of the list.

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
3
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5

Python3

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
7
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
71
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
9
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
90__191919192

Input : list1 = [3, 2, 4] 
Output : 24 
0
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
8

Input : list1 = [3, 2, 4] 
Output : 24 
9
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
6
24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
8

2

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4 5
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
07
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
08

5

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4 5
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
07
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
08

6
24 
8 9

6
24 
8 1

Phương pháp 4 Sử dụng chức năng Prod của Thư viện toán học: Sử dụng Math.ProdUsing prod function of math library: Using math.prod

Bắt đầu Python 3.8, một hàm prod đã được đưa vào mô -đun toán học trong thư viện tiêu chuẩn, do đó không cần phải cài đặt các thư viện bên ngoài.

Dưới đây là triển khai Python3 của cách tiếp cận trên: & nbsp; & nbsp;

Python3

6
24 
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
25

Input : list1 = [3, 2, 4] 
Output : 24 
0
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
8

Input : list1 = [3, 2, 4] 
Output : 24 
9
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
6
24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
8

2

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4 5
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
07
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
08

5

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4 5
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
07
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
08

6
24 
8 9

6
24 
8 1

Output:   
 

6
24 

6
24 
8 1Using mul[] function of operator module. 

Phương pháp 4 Sử dụng chức năng Prod của Thư viện toán học: Sử dụng Math.Prod

Python3

Bắt đầu Python 3.8, một hàm prod đã được đưa vào mô -đun toán học trong thư viện tiêu chuẩn, do đó không cần phải cài đặt các thư viện bên ngoài.

Input : list1 = [3, 2, 4] 
Output : 24 
0
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
8

Dưới đây là triển khai Python3 của cách tiếp cận trên: & nbsp; & nbsp;

6
24 
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
25

2

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
46

6
24 
8
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
79

5

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
49
Using traversal by index

Python3

Phương pháp 5: Sử dụng hàm mul [] của mô -đun toán tử. & Nbsp;

Đầu tiên chúng ta phải nhập mô -đun toán tử sau đó sử dụng hàm mul [] của mô -đun toán tử nhân tất cả các giá trị trong danh sách. & NBSP;

2

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
55
6
24 
22

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
67
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
7
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
71
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
9
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
73

Input : list1 = [3, 2, 4] 
Output : 24 
0
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
8

Input : list1 = [3, 2, 4] 
Output : 24 
9
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
6
24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
8

6
24 
8
6
24 
9

6
24 
8
6
24 
1

2

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4 5
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
07
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
08
Using itertools.accumulate

5
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4 5
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
07
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
08

6
24 
8 1

Input : list1 = [3, 2, 4] 
Output : 24 
0
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
8

Input : list1 = [3, 2, 4] 
Output : 24 
9
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4
Input : list1 = [3, 2, 4] 
Output : 24 
2
Input : list1 = [3, 2, 4] 
Output : 24 
7
Input : list1 = [3, 2, 4] 
Output : 24 
4
Input : list1 = [3, 2, 4] 
Output : 24 
5
Input : list1 = [3, 2, 4] 
Output : 24 
4
6
24 
6
Input : list1 = [3, 2, 4] 
Output : 24 
8

2

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4 5
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
07
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
08

5

# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
4 5
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
07
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
08

6
24 
8
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
66
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
67
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
69

6
24 
8
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
71
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
67
# Take input from user
num = int[input["Enter any number : "]]

temp = num
product = 1;

while[temp != 0]:

    product = product * [temp % 10];

    # Remove last digit from temp.
    temp = int[temp / 10]

print["\nProduct of all digits in", num, ":", product]
5
Input :  list1 = [1, 2, 3] 
Output : 6 
Explanation: 1*2*3=6 
69

Output:

6
24

Làm thế nào để bạn tìm thấy sản phẩm trong Python?

Chúng ta có thể sử dụng numpy.prod [] từ nhập khẩu numpy để có được sự nhân của tất cả các số trong danh sách.Nó trả về một số nguyên hoặc giá trị float tùy thuộc vào kết quả nhân.numpy. prod[] from import numpy to get the multiplication of all the numbers in the list. It returns an integer or a float value depending on the multiplication result.

Làm thế nào để bạn tìm thấy sản phẩm của N số trong Python?

Sản phẩm của các chữ số của số sử dụng Python..
Thiết kế biểu đồ dòng chảy ..
Chương trình hoặc giải pháp.num = int [input ["nhập một số"]] n = num.....
Output..
Giải thích chương trình.Khởi tạo sản phẩm bằng 1 ..

Làm thế nào để tôi tìm thấy sản phẩm của một số?

Bạn có thể tìm thấy từng sản phẩm của một số bằng cách nhân nó với một số khác.Ví dụ, 27 là một sản phẩm 9 và 3, vì 9 x 3 = 27. Lượng sản phẩm tiềm năng của mỗi số là vô hạn, vì chúng có thể được nhân với một lựa chọn vô hạn của các số khác để đạt được số lượng câu trả lời vô hạn.multiplying it by another number. For example, 27 is a product of 9 and 3, because 9 x 3 = 27. The amount of potential products of each number is infinite, since they could be multiplied by an infinite selection of other numbers to reach an infinite number of answers.

Có một chức năng sản phẩm trong Python?

Phương thức prod [] trong python được sử dụng để tính toán sản phẩm của tất cả các yếu tố có trong số đó đã cho..

Chủ Đề