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
51Input : 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=651
Input : list1 = [1, 2, 3] Output : 6 Explanation: 1*2*3=660
# 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=61
# 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=65
Input : list1 = [1, 2, 3] Output : 6 Explanation: 1*2*3=601
# 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=68
Input : list1 = [1, 2, 3] Output : 6 Explanation: 1*2*3=69
Input : list1 = [3, 2, 4] Output : 240
# 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 : 242
# 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 : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 248
# 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 248
6 249
6 248
6 241
# 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]
73Using 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 : 240
# 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 : 242
# 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 : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 248
# 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 248
96 248
1Output:
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 : 240
# 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 : 242
# 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 : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 248
Input : list1 = [3, 2, 4] Output : 249
# 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 : 242
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
6 246
Input : list1 = [3, 2, 4] Output : 248
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 248
96 248
1Phươ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 242
# 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 : 240
# 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 : 242
# 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 : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 248
Input : list1 = [3, 2, 4] Output : 249
# 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 : 242
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
6 246
Input : list1 = [3, 2, 4] Output : 248
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 248
96 248
1Output:
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 : 240
# 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 : 242
# 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 : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 248
Dưới đây là triển khai Python3 của cách tiếp cận trên: & nbsp; & nbsp;
6 242
# 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 248
# 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 2422
# 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 : 240
# 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 : 242
# 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 : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 248
Input : list1 = [3, 2, 4] Output : 249
# 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 : 242
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
6 246
Input : list1 = [3, 2, 4] Output : 248
6 248
6 249
6 248
6 241
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]
08Using 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 248
1Input : list1 = [3, 2, 4] Output : 240
# 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 : 242
# 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 : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 248
Input : list1 = [3, 2, 4] Output : 249
# 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 : 242
Input : list1 = [3, 2, 4] Output : 247
Input : list1 = [3, 2, 4] Output : 244
Input : list1 = [3, 2, 4] Output : 245
Input : list1 = [3, 2, 4] Output : 244
6 246
Input : list1 = [3, 2, 4] Output : 248
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 248
Input : list1 = [1, 2, 3] Output : 6 Explanation: 1*2*3=666
Input : list1 = [1, 2, 3] Output : 6 Explanation: 1*2*3=667
# 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=669
6 248
Input : list1 = [1, 2, 3] Output : 6 Explanation: 1*2*3=671
Input : list1 = [1, 2, 3] Output : 6 Explanation: 1*2*3=667
# 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=669
Output:
6 24