I have written a code following the instructions below, but the choice 2, convert Fahrenheit to Celsius, does not return to input_value = float(input("Please enter how much {0} would you like to convert into {1}: ".format(metric_name[choice-1] , convert_name[choice-1]))), to ask user for enter another value. Can you clarify me why? What am I doing wrong? Thank you. The code is shown below. For this portion of the lab, you will reuse the program you wrote before.That means you will open the lab you wrote in the previous assignment and change it. You should NOT start from scratch. Also, all the requirements/prohibitions from the previous lab MUST also be included /omitted from this lab. Redesign the solution in the following manner:  1. All the functions used are value-returning functions. 2. Put the functions in an external module and let the main program import the module. #Conversions.py def MilesToKm(Miles):       Km = Miles * 1.6       print(f"Miles: {format(Miles,'.2f')}, kilometers: {format(Km,'.2f')}")def FahToCel(Fahrenheit):       Celsius = (Fahrenheit - 32) * 5 / 9       print(f"farehnheit: {format(Fahrenheit,'.2f')}, celsius: {format(Celsius,'.2f')}")def GalToLit(Gallons):       Liters = Gallons * 3.9       print(f"gallons: {format(Gallons,'.2f')}, liters: {format(Liters,'.2f')}")def PoundsToKg(Pounds):       Kg = Pounds * 3.45       print(f"pounds: {format(Pounds,'.2f')}, kilograms: {format(Kg,'.2f')}")def InchesToCm(Inches):       Cm = Inches * 2.54       print(f"inches: {format(Inches,'.2f')}, centimeters: {format(Cm,'.2f')}")   from Conversions import *#Create main function to give choice of conversiondef main():   string = '''   1: Convert miles to km   2: Convert fahrenheit to celsius   3: Convert gallons to liters   4: Convert pounds to kg   5: Convert inches to cm'''   metric_name = ('miles','fahrenheit','gallons','pounds','inches')   convert_name = ('km','celsius','liters','kg','cm')   print(string)   choice = int(input('Enter your choice: '))   count = 3   flag = True   while(flag):       input_value = float(input("Please enter how much {0} would you like to convert into {1}: ".format(metric_name[choice-1] , convert_name[choice-1])))       if choice ==2:           if input_value >= 1000:               count -= 1               print('Invalid input! You have',count,'chance(s) to enter a valid input')           else:               FahToCel(input_value)               flag = False       else:           if input_value < 0:               count -= 1               print('Invalid input! You have',count,'chance(s) to enter a valid input')           else:               if choice == 1:                   MilesToKm(input_value)               if choice == 3:                   GalToLit(input_value)               if choice == 4:                   PoundsToKg(input_value)               if choice == 5:                   InchesToCm(input_value)           if count == 0:               flag = Falsemain()

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question
100%

I have written a code following the instructions below, but the choice 2, convert Fahrenheit to Celsius, does not return to input_value = float(input("Please enter how much {0} would you like to convert into {1}: ".format(metric_name[choice-1] , convert_name[choice-1]))), to ask user for enter another value. Can you clarify me why? What am I doing wrong? Thank you.

The code is shown below.

For this portion of the lab, you will reuse the program you wrote before.
That means you will open the lab you wrote in the previous assignment and change it. You should NOT start from scratch. Also, all the requirements/prohibitions from the previous lab MUST also be included /omitted from this lab.
Redesign the solution in the following manner: 

1. All the functions used are value-returning functions.

2. Put the functions in an external module and let the main program import the module.

#Conversions.py
def MilesToKm(Miles):
       Km = Miles * 1.6
       print(f"Miles: {format(Miles,'.2f')}, kilometers: {format(Km,'.2f')}")
def FahToCel(Fahrenheit):
       Celsius = (Fahrenheit - 32) * 5 / 9
       print(f"farehnheit: {format(Fahrenheit,'.2f')}, celsius: {format(Celsius,'.2f')}")
def GalToLit(Gallons):
       Liters = Gallons * 3.9
       print(f"gallons: {format(Gallons,'.2f')}, liters: {format(Liters,'.2f')}")
def PoundsToKg(Pounds):
       Kg = Pounds * 3.45
       print(f"pounds: {format(Pounds,'.2f')}, kilograms: {format(Kg,'.2f')}")
def InchesToCm(Inches):
       Cm = Inches * 2.54
       print(f"inches: {format(Inches,'.2f')}, centimeters: {format(Cm,'.2f')}")
 

from Conversions import *
#Create main function to give choice of conversion
def main():
   string = '''
   1: Convert miles to km
   2: Convert fahrenheit to celsius
   3: Convert gallons to liters
   4: Convert pounds to kg
   5: Convert inches to cm'''
   metric_name = ('miles','fahrenheit','gallons','pounds','inches')
   convert_name = ('km','celsius','liters','kg','cm')
   print(string)
   choice = int(input('Enter your choice: '))
   count = 3
   flag = True
   while(flag):
       input_value = float(input("Please enter how much {0} would you like to convert into {1}: ".format(metric_name[choice-1] , convert_name[choice-1])))
       if choice ==2:
           if input_value >= 1000:
               count -= 1
               print('Invalid input! You have',count,'chance(s) to enter a valid input')
           else:
               FahToCel(input_value)
               flag = False
       else:
           if input_value < 0:
               count -= 1
               print('Invalid input! You have',count,'chance(s) to enter a valid input')
           else:
               if choice == 1:
                   MilesToKm(input_value)
               if choice == 3:
                   GalToLit(input_value)
               if choice == 4:
                   PoundsToKg(input_value)
               if choice == 5:
                   InchesToCm(input_value)
           if count == 0:
               flag = False
main()

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 9 steps with 8 images

Blurred answer
Knowledge Booster
Datatypes
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education