In: Computer Science
Python
Create a Python script file called hw3.py.
Ex. 1. Write a program that inputs numbers from the user until they enter a 0 and computes the product of all these numbers and outputs it.
Hint: use the example from the slides where we compute the sum of a list of numbers, but initialize the variable holding the product to 1 instead of 0.
print("Enter n") n = int(input()) min = n while n != 0: if n < min: min = n print("Enter n") n = int(input()) print("The minimum of the list is", min)
The code is ___________________________________________________________________________________________________
print("Enter the value of n")
n = int(input()) ## taking the first input of n
if n == 0 : ## checking if the first n is 0
print("The product of the above numbers is 0")
else :
product = 1 ## initialising product as 1
while n != 0 : ## checking n is not equal to 0
product=product*n ## multiplying the product with n
print("Enter the value of n")
n = int(input())
print("The product of the above numbers", product) ## printing the
final product
The code snippet with running examples:
----------------------------------------------------------------------------------------------------------------------------------------------------------------------
First case when the first value of n is 0 :
--------------------------------------------------------------------------------------------------------------------------------------------------------------Second case when the values of n are 10,33,2,0 :