1、 The code for multiplying in Python:
sum =1;
n =int(input("Please input number n:"))for i inrange(1,n+1):
sum = sum*i;if i<n:print(i,end='')print("*",end ='')print(i,"=",sum)
2、 operation result
Example extension:
Python multiplying recursive parameters can be multiple iterable objects
from functools import reduce
a =(1,2,3,['1','1'],[1,[2,[3,[4]]]])
def args_all_to_list(*args):try:
data=list(*args)return data
except:
data=list(args)return data
def data_list(a):
data =[]
f =0for x in a:iftype(x) is int:
data.append(x)
f +=1
elif type(x) is str:
data.append(int(x))
elif type(x) is list or tuple:
data +=list(x)if f ==len(a):return data
returndata_list(data)
def chen(*args):returnreduce(lambda x, y: x * y,data_list(args_all_to_list(*args)))print(chen(1,2))print(chen(1,2,[1]))print(chen(a))
So far this article on how to perform continuous multiplication calculations in python is introduced here. For more code content related to continuous multiplication calculations in python, please search ZaLou.Cn
Recommended Posts