How to perform continuous multiplication calculation in python

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

How to perform continuous multiplication calculation in python
How to wrap in python code
How to omit parentheses in Python
How to write classes in python
How to filter numbers in python
How to read Excel in Python
How to view errors in python
How to write return in python
How to understand variables in Python
How to clear variables in python
How to use SQLite in Python
How to use and and or in Python
How to delete cache files in python
How to introduce third-party modules in Python
How to represent null values in python
How to save text files in python
How to write win programs in python
How to run id function in python
How to install third-party modules in Python
How to custom catch errors in python
How to write try statement in python
How to define private attributes in Python
How to add custom modules in Python
How to understand global variables in Python
How to view installed modules in python
How to open python in different systems
How to sort a dictionary in python
How to add background music in python
How to represent relative path in python
How to use the round function in python
How to use the zip function in Python
How to program based on interfaces in Python
How to install python in ubuntu server environment
How to simulate gravity in a Python game
How to use the format function in python
How to use code running assistant in python
How to set code auto prompt in python
Teach you how to write games in python
How to delete files and directories in python
How to install the downloaded module in python
How to write a confession program in python
How to understand the introduction of packages in Python
How to understand a list of numbers in python
Example of how to automatically download pictures in python
How to save IE as an attachment in python
How to create a Python virtual environment in Ubuntu 14.04
How to comment python code
How to learn python quickly
How to uninstall python plugin
How to understand python objects
How to use python tuples
How to find the area of a circle in python
Do you still know how to draw cakes in python? ? ?
How does python perform matrix operations
How to install Helm in Ubuntu
python how to view webpage code
How to use hanlp in ubuntu
How to use python thread pool
How to write python configuration file
How to install PHP7.4 in CentOS
How to save the python program