Question

In: Computer Science

Python Create a Python script file called hw3.py. Ex. 1. Write a program that inputs numbers...

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)

Solutions

Expert Solution

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 :


Related Solutions

Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user...
Write a Python program stored in a file q3.py that: Gets single-digit numbers from the user on one line (digits are separated by white space) and adds them to a list. The first digit and the last digit should not be a zero. If the user provides an invalid entry, the program should prompt for a new value. Converts every entry in the list to an integer and prints the list. The digits in the list represent a non-negative integer....
Using Python create a script called create_notes_drs.py. In the file, define and call a function called...
Using Python create a script called create_notes_drs.py. In the file, define and call a function called main that does the following: Creates a directory called CyberSecurity-Notes in the current working directory Within the CyberSecurity-Notes directory, creates 24 sub-directories (sub-folders), called Week 1, Week 2, Week 3, and so on until up through Week 24 Within each week directory, create 3 sub-directories, called Day 1, Day 2, and Day 3 Bonus Challenge: Add a conditional statement to abort the script if...
Write a script called script2-4.py that takes a person's delivery order as inputs, totals all the...
Write a script called script2-4.py that takes a person's delivery order as inputs, totals all the items and calculates the tax due and the total due. The number of inputs is not known. You can assume that the input is always valid. (i.e no negative numbers or string like "cat"). Use a loop that takes the prices of items as parameters that are floats, counts the number of items, and sums them to find the total. You must also use...
Write a script called script2-4.py that takes a person's delivery order as inputs, totals all the...
Write a script called script2-4.py that takes a person's delivery order as inputs, totals all the items and calculates the tax due and the total due. The number of inputs is not known. You can assume that the input is always valid. (i.e no negative numbers or string like "cat"). Use a loop that takes the prices of items as parameters that are floats, counts the number of items, and sums them to find the total. You must also use...
Write a script called script2-4.py that takes a person's delivery order as inputs, totals all the...
Write a script called script2-4.py that takes a person's delivery order as inputs, totals all the items and calculates the tax due and the total due. The number of inputs is not known. You can assume that the input is always valid. (i.e no negative numbers or string like "cat"). Use a loop that takes the prices of items as parameters that are floats, counts the number of items, and sums them to find the total. You must also use...
Using Python Shell 2.7, create a file called Assignment6_1.py Create an array based on a basic...
Using Python Shell 2.7, create a file called Assignment6_1.py Create an array based on a basic array Create a for loop that will print the array index the array, print out the index append an element to the array, print out the array insert an element into the array, print out the array pop an element from the array, print out the array remove an element from the array, print out the array reverse the order of the array, print...
Write a python program: There is a file called file 2. File2 is a txt file...
Write a python program: There is a file called file 2. File2 is a txt file and I have written the contents of file 2 below in the exact format it was in notepad. # This comment does not make sense # It is just to make it harder # The job description starts after this comment, notice that it has 4 lines. # This job description has 700150 hay system points\\ the incumbent will administer the spending of kindergarden...
Create a geoprocessing tool from the .py file included (script from this file included below). Use...
Create a geoprocessing tool from the .py file included (script from this file included below). Use any csv file you would like. I will work around that. This is for a programming for GIS class. We work with jupyter, idle, arcgis pro import os import arcpy from arcpy import env input_table = r"C:\Answers\January2018.CSV" output_fc = r"C:\Answers\crime.gdb\January2018_Crime" spRef = arcpy.SpatialReference("NAD 1983 StatePlane Missouri East FIPS 2401 (US Feet)") gdb_name = os.path.dirname(output_fc) fc_name = os.path.basename(output_fc) env.overwriteOutput = True print("Creating File GDB") arcpy.CreateFileGDB_management(os.path.dirname(gdb_name),...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program:...
Create a Python script in IDLE or Kali Python3 CLI to create the following Python Program: Your program will create a username of your choice using a Kali Linux command "useradd -m mark", then set the password for that user using the Kali Linux Command "echo "mark:10101111" | chpasswd". Then you create a dictionary file using the Kali Linux command "crunch 8 8 01 > mylist.txt" Your python script should crack the password for that user and display on the...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file...
Problem: Write a Python module (a text file containing valid Python code) named p5.py. This file must satisfy the following. Define a function named rinsert. This function will accept two arguments, the first a list of items to be sorted and the second an integer value in the range 0 to the length of the list, minus 1. This function shall insert the element corresponding to the second parameter into the presumably sorted list from position 0 to one less...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT