Product of N numbers. Given an integer N followed by N integers, read these integers and print their product. The first line of input contains a positive integer N, which indicates how many integers will follow. Each of the next N lines contains one integer. Calculate and print the product of these N integers.
|
product = 1 for _ in range(N): product *= int(input()) print(product) |
- Reading the Number of Integers:
- The
input()
function reads the first line of input.
- The
int()
function converts this input to a positive integer and stores it in the variable N
.
- Initialize the Product:
- A variable
product
is initialized to 1. This will be used to store the product of the N integers.
- Reading and Multiplying Integers:
for _ in range(N):
product *= int(input())
- A
for
loop runs N
times, as indicated by range(N)
.
- Each iteration reads a number from the user using
input()
, converts it to an integer with int()
, and multiplies it to product
.
- Printing the Total Product:
- Finally, the
print()
function outputs the value of product
.