Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using python, write code for problem. The text file Units.txt is used in this pr

ID: 3847964 • Letter: U

Question

Using python, write code for problem. The text file Units.txt is used in this problem and i have pasted contents of the file. Please also put screenshot of your code.

1. Unit Conversions Table 5.5 contains some lengths in terms of feet. Write a program that displays the nine different units of measure; requests the unit to convert from, the unit to convert to, and the quantity to be converted; and then displays the converted quantity. A typical outcome is shown in Fig. 5.47. Use the file Units.txt to create a dictionary that provides the number of feet for a given unit of length. The first two lines of the file are inches, 083333 furlongs ,660 TABLE 5.5 Equivalent lengths 1 inch 083333 foot 1 rod 16.5 feet 1 yard 3 feet 1 meter 3.28155 feet 1 kilometer 3281.5 feet 1 fathom 6 feet 1 mile 5280 feet UNITS OF LENGTH inches furlongs yards rods miles fathoms feet kilometers meters Units to convert from yards Units to convert to miles Enter length in yards: 555 Length in miles 0.3153 FIGURE 5.47 Possible outcome of Programming Project 1.

Explanation / Answer

python 2.7 code:

print "Units of Length"
print "feets inches furlongs"
print "yards fathoms feet"
print "kilometers meters miles rods"
mydict1 = {"feet":1,"inches":0.083333,"furlongs":660,"yards":3,"fathoms":6,"feet":1,"kilometers":3281.5,"meters":3.2815,"miles":5280,"rods":16.5}
print "Enter unit to convert from"
us = raw_input().strip()
print "Enter unit to convert to"
ud = raw_input().strip()
print "Enter length in", us
us_value = float(raw_input().strip())
if(us in mydict1):
   if(ud in mydict1):
       us_to_feet = (mydict1[us])*us_value
       feet_to_ud = (1/float(mydict1[ud]))*us_to_feet
       print "Length in ", ud, feet_to_ud
   else:
       print "Invalid Unit", d2  
else:
   print "Invalid Unit", us

Sample Output:

Units of Length
feets inches furlongs
yards fathoms feet
kilometers meters miles rods
Enter unit to convert from
yards
Enter unit to convert to
miles
Enter length in yards
555
Length in miles 0.315340909091

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote