Question

In: Computer Science

For this portion of the lab you will design the solution so that you perform some...

For this portion of the lab you will design the solution so that you perform some conditional tests. For this lab: 1. You will validate input to ensure that the user enters inputs within a certain range or larger than a certain minimum value. You will validate the inputs as follows: (LO 1, 2, 3) a. The user cannot enter a negative number for: i. Miles to kilometers ii. Gallons to liters iii. Pounds to kilograms iv. Inches to centimeters b. The user cannot enter a value above 1000 degrees for Fahrenheit to Celsius (LO1) c. You MUST design a logical program exit. You may NOT use exit, break, quit, or system exit, or ANY OTHER forced exit. Do not use a menu. Use LOGIC to exit the program. 2. If the user enters an invalid value, then the program will issue an error message and terminate immediately. (Do NOT accept further data). 3. Save the program as firstname_lastname_Lab3a.py where you will replace firstname and lastname with your actual first and last name. 4. Test all conditions prior to submitting.

Solutions

Expert Solution

Screenshot of the code:

Sample Output:

#Sample Run 1:

#Sample Run 2:

#Sample Run 3:

#Sample Run 4:

#Sample Run 5:

Code To Copy:

#Run the code in python version 3.x.

#Indent the code before executing as per the above screenshot of the code.

#Otherwise it may give error. Indentation is important in python.

#Prompt the user to enter the miles.

Miles = float(input('Enter the miles to convert into kilometer: '))

#Check the miles.

if Miles >= 0 :

    #Convert the miles to kilometers.

    Miles_To_km = Miles*1.6

    #Display the result.

    print (Miles, "miles equivalent to", Miles_To_km, "kilometer.")

    #Prompt the user to enter the gallons.

    Gallon = float(input('Enter the gallons to convert into liter: '))

    #Check the validity of the Gallons entered.

    if Gallon >= 0:

        #Convert gallons into liters.

        Gal_To_Lit = Gallon*3.9

        #Display the result.

        print (Gallon, "gallons equivalent to", Gal_To_Lit, "liters.")

        #Prompt the user to enter the pounds.

        Pound = float(input('Enter the pounds to convert into kilograms: '))

        #Check the validity of the Pounds entered.

        if Pound >= 0:

            #Convert pounds into kilograms.

            Pounds_To_Kg = Pound*0.45

            #Display the result.

            print (Pound, "pounds equivalent to", Pounds_To_Kg, "kilograms.")

            #Prompt the user to enter the temperature in Fahrenheit.

            f = float(input('Enter the temperature in Fahrenheit: '))

            #Check the value to be not greater than 1000.

            if f < 1000:

                #Convert Fahrenheit into celsius.

                F_To_C = (f -32)*5/9

                #Display the result.

                print (f, "Fahrenheit equivalent to", F_To_C, "celsius.")

            #Otherwise.

            else:

               

                #Display the error message.

                print ("Invalid temperature (greater than 1000) !!!")

        else:

            #Display the error message.

            print ("Pounds cannot be negative !!!")

    else:

            #Display the error message.

            print ("Gallons cannot be negative !!!")

else:

    #Display the error message.

    print ("Miles cannot be negative !!!")


Related Solutions

In the buffer portion of the lab, you compared how water and a buffer solution react...
In the buffer portion of the lab, you compared how water and a buffer solution react to the addition of base (NaOH) and acid (HCl). Based on your observations, which seems to have greater “buffering capacity” (ability to maintain a consistent pH): the distilled water or the buffer? The buffer solution consisted of acetic acid and sodium acetate (of which, the acetate ion is the important species). Of this mixture, the weak acid is _____ _____ and its conjugate base...
Design an experiment that you could perform in our lab to determine the coefficient of kinetic...
Design an experiment that you could perform in our lab to determine the coefficient of kinetic friction and static friction and to compare the coefficient of kinetic friction and static friction. A good design should include details of the materials and equipment needs, the experimental procedure, including precautions, the types of data you will collect, how the data will be represented and analyzed, and how you will determine the accuracy of your experimental result(s).
Design an experiment in which you would perform some sort of hypothesis test about frequencies. For...
Design an experiment in which you would perform some sort of hypothesis test about frequencies. For your chosen experiment, explain your entire experimental design. What is your population of interest? How are you going to randomly sample the pop? How many replicates will you collect? What will be the form of the data you collect and what test will you perform? What is your null and alternative hypothesis?
MA 117 Lab 1 In this lab, you will need to write equations, perform calculations, and...
MA 117 Lab 1 In this lab, you will need to write equations, perform calculations, and make judgements. All equations and calculations should be included in your lab write-up. All judgements should be explained and justified in complete sentences referencing your calculations. Hospital Administration Southwest Hospital has an operating room used only for eye surgery. The annual cost of rent, heat, and electricity for the operating room and its equipment is $360,000, and the annual salaries of the people who...
Question: You perform a lab where you are instructed to observe the characteristics of a lipid...
Question: You perform a lab where you are instructed to observe the characteristics of a lipid molecule in oil and water and are told to conduct 3 trials each time for the lab. You noticed that you get the same observations for all 3 trials for the lab. Explain in detail why you were asked to complete 3 trials? Why were you not asked to complete 1 trial?
If you were to perform this reaction in a lab, you would make far less than...
If you were to perform this reaction in a lab, you would make far less than the theoretical yield of product due to a wide range of outside factors. We can compare the actual yield to the theoretical yield to calculate the percent yield: percent yield=actual yieldtheoretical yield×100% Keep in mind that the percent yield can be calculated using any unit of mass or moles, so long as they are the same. For example, you can divide moles by moles,...
Perform some research and explore the term 'Responsive Design'.  What does it mean and what level of...
Perform some research and explore the term 'Responsive Design'.  What does it mean and what level of importance would you assign to in in your web design considerations? What impact do you think it will have on your Web Development endeavors? Why?
You are provided with the following portion of a protocol: Determine concentration of enzyme stock solution,...
You are provided with the following portion of a protocol: Determine concentration of enzyme stock solution, if unknown, by taking an A280 nm reading of a 1:100 dilution (in water). Use a total volume of 1 ml in the cuvette. Dilute some of the enzyme stock with buffer A to make a 4 mg/ml solution. Serially dilute the 4 mg/ml solution with buffer A to make working solutions of 400 µg/ml and 40 µg/ml. Prepare 30 µl of each working...
Imagine that you are in chemistry lab and need to make 1.00L of a solution with...
Imagine that you are in chemistry lab and need to make 1.00L of a solution with a pH of 2.40. You have in front of you 100 mL of 6.00
How to design an experiment In a lab, you will have access to a mystery metal,...
How to design an experiment In a lab, you will have access to a mystery metal, a string, a retort stand, a beaker, a kettle, water, two thermometers, a stopwatch, a weight scale, and an insulated container with cup and lid. The metal can be submerged in the container of water such that the water provides a temperature bath for the metal. Design determine the specific heat capacity of the mystery metal. In your preparatory assignment: brass an experiment that...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT